我正在 ping 服务器以获取JSON
响应。这是响应的样子:
{
"notifications":{
"0":{
"id":"17546",
"uID":"6698",
"text":"Earned 22 points for searching",
},
"1":{
"id":"17545",
"uID":"6698",
"text":"Earned 1 point for searching",
},
"2":{
"id":"17544",
"uID":"6698",
"text":"Earned 1 point for searching",
},
"3":{
"id":"17543",
"uID":"6698",
"text":"Earned 1 point for searching",
},
"4":{
"id":"17528",
"uID":"6698",
"text":"Earned 1 point for searching",
},
"notificationCount":5
} }
我收到了从服务器收到的全部通知。我怎样才能将其用于我的目的。
我必须解析“文本”获取text
并将其粘贴到视图上。我做错了。这是我所做的:
JSONObject jNotification0 = jSearchData.getJSONObject("0");
JSONObject jNotification1 = jSearchData.getJSONObject("1");
JSONObject jNotification2 = jSearchData.getJSONObject("2");
JSONObject jNotification3 = jSearchData.getJSONObject("3");
JSONObject jNotification4 = jSearchData.getJSONObject("4");
String jText0 = jNotification0.getString("text");
String jText1 = jNotification1.getString("text");
String jText2 = jNotification2.getString("text");
String jText3 = jNotification3.getString("text");
String jText4 = jNotification4.getString("text");
TextView notificationText1 = (TextView) dialogLoggedInNotification.findViewById(R.id.notificationText1);
TextView notificationText2 = (TextView) dialogLoggedInNotification.findViewById(R.id.notificationText2);
TextView notificationText3 = (TextView) dialogLoggedInNotification.findViewById(R.id.notificationText3);
TextView notificationText4 = (TextView) dialogLoggedInNotification.findViewById(R.id.notificationText4);
TextView notificationText5 = (TextView) dialogLoggedInNotification.findViewById(R.id.notificationText5);
notificationText1.setText(jText0);
notificationText2.setText(jText1);
notificationText3.setText(jText2);
notificationText4.setText(jText3);
notificationText5.setText(jText4);
我想这不是我应该进行解析的方式。请指导我。
任何形式的帮助将不胜感激。