Possible Duplicate:
Reading a Json Array in android
我的json字符串就像
字符串jsonString =
“ [{” NotificationID“:115,” TaskID“:129,” Sender“:” v ... @ live.com“,” NotificatonMessage“:” dd“,” NotificationCategory“:” missed“},{” NotificationID “:114,” TaskID“:129,”发件人“:” v ... @ live.com“,” NotificatonMessage“:” 129“,” NotificationCategory“:”已打开“},{” NotificationID“:112,” TaskID“:129,” Sender“:” v ... @ live.com“,” NotificatonMessage“:” dd“,” NotificationCategory“:” missed“},{” NotificationID“:111,” TaskID“:129, “发件人”:“ d ... @ hotmail.com”,“ NotificatonMessage”:“您
已分配任务
Bydip_shres@hotmail.com“,” NotificationCategory“:” notify“},{” NotificationID“:72,” TaskID“:125,” Sender“:” d ... @ yahoo.com“,” NotificatonMessage“:”您
已分配任务
Byd.stha1st@yahoo.com“,” NotificationCategory“:” notify“}]”;
我想将其转换为jsonobject。我正在做..
jsonObject = new JSONObject(jsonString);
但是它抛出JSONException ...我怎么能把这样的字符串转换成jsonarray?
最佳答案
使用此代码及更多信息JSONParsing
引用此Link
这将对您有所帮助。
try
{
JSONArray jArray = new JSONArray(jsonString);
for(int i=0;i<jArray.length();i++)
{
JSONObject jsonObj = jArray.getJSONObject(i);
String NotificationID =jsonObj.getString("NotificationID");
String TaskID=jsonObj.getString("TaskID");
String Sender=jsonObj.getString("Sender");
String NotificatonMessage=jsonObj.getString("NotificatonMessage");
String NotificationCategory=jsonObj.getString("NotificationCategory");
}
}
catch(JSONException e)
{
Log.e("log_tag", "Error parsing data "+e.toString());
}