我有響應怎樣的JSONObject轉換爲JSonArray ......?
{
"p1":{
"date":"Sat, 29 Jul 2017 03:31:43 GMT",
"plan_id":"5c4c6548-38cb-4dbb-b7a3-a3f260fb8532",
"plan_name":"Ultra50",
"pulse":1,
"tarrif":1,
"validity":30
},
"p2":{
"date":"Sat, 29 Jul 2017 03:31:43 GMT",
"plan_id":"5c4c6548-38cb-4dbb-b7a3-a3f260fb8532",
"plan_name":"Ultra50",
"pulse":1,
"tarrif":1,
"validity":30
}
}
這裏我的代碼
Response.Listener<JSONObject> responseListener = new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONObject plan=response.getJSONObject("p1");
Iterator x=plan.keys();
JSONArray jsonElements=new JSONArray();
while (x.hasNext()){
String key=(String) x.next();
jsonElements.put(plan.get(key));
Log.e(TAG, "onResponse: "+key);
}
Log.d(TAG, "onResponse: "+jsonElements.toString());
} catch (JSONException e) {
e.printStackTrace();
}
如何P1,P2,P3轉換一個JsonArray?
您的問題不清楚。 –
我想在此列表視圖JSON響應......這可能嗎? @IntelliJAmiya –
是的。爲什麼不.. –