我有这个json
{
"where":"{}",
"expiry":1451606400,
"data":{
"alert":"alert_message",
"names":["john","paul","frank","bill"],
"action":"com.fidelizacion.UPDATE_STATUS"
}
}
在我的Android应用程序中,我解析了这样的json数据:
String action = intent.getAction();
String channel = intent.getExtras().getString("com.parse.Channel");
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
Iterator itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
Log.d(TAG, "..." + key + " => " + json.getString(key));
}
和日志显示
action => com.fidelizacion.UPDATE_STATUS
alert => alert_message
names => ["john","paul","frank","bill"]
但我想声明一个包含我收到的名字的数组。任何想法
答案 0 :(得分:0)
您可以获取JSONArray对象:
JSONArray arr = json.getJSONArray("names");
int len = arr.length();
String[] names = new String[len];
for (int i = 0; i < len; i++) {
names[i] = arr.getString(i);
}