Try this..
try {
Object obj = new JSONTokener(test).nextValue();
if (obj instanceof JSONObject)
//you have an object
else if (obj instanceof JSONArray)
//you have an array
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}