对于我的一项网络服务,我收到以下响应。
"COLUMNS": [
"DIST_ID",
"NAME",
"HOME_PHONE",
"PAID_RANK",
"END_RANK",
"VOL1",
"VOL3"
]
"DATA": {
"DIST_ID": [
3,
1002,
1040,
1290,
1041,
1421,
7200,
5980,
3962,
1070,
9369,
]
}
我该如何解析这个?
我试过了
JSONArray colArray = response.getJSONArray(COLUMNS);
for(int i=0; i<colArray.length(); i++){
if(Constants.LOG)Log.d("","Column "+colArray.getJSONObject(i).toString());
}
但它没有奏效。它抛出异常
09-30 12:51:56.076: W/System.err(3003): org.json.JSONException: Value DIST_ID at 0 of type java.lang.String cannot be converted to JSONObject
09-30 12:51:56.076: W/System.err(3003): at org.json.JSON.typeMismatch(JSON.java:96)
09-30 12:51:56.076: W/System.err(3003): at org.json.JSONArray.getJSONObject(JSONArray.java:484)
09-30 12:51:56.076: W/System.err(3003): at com.vl.infotrax.modules.reports.ReportsEngine.parseReportsDetailsData(ReportsEngine.java:156)
09-30 12:51:56.076: W/System.err(3003): at com.vl.infotrax.modules.reports.ReportsEngine.retrieveReportsDetailsData(ReportsEngine.java:126)
09-30 12:51:56.076: W/System.err(3003): at com.vl.infotrax.modules.reports.ReportsDetailsFragment$GetReportsDetailsData.doInBackground(ReportsDetailsFragment.java:66)
09-30 12:51:56.076: W/System.err(3003): at com.vl.infotrax.modules.reports.ReportsDetailsFragment$GetReportsDetailsData.doInBackground(ReportsDetailsFragment.java:1)
09-30 12:51:56.084: W/System.err(3003): at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-30 12:51:56.084: W/System.err(3003): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-30 12:51:56.084: W/System.err(3003): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-30 12:51:56.084: W/System.err(3003): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
09-30 12:51:56.084: W/System.err(3003): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
09-30 12:51:56.084: W/System.err(3003): at java.lang.Thread.run(Thread.java:1096)
任何人都知道如何解决这个问题?提前致谢。