我有这样的Json结果:array.getJSONObject(j)-
{“ ExecutiveCode”:“ WAT2”,“ FreeIssuePrefix”:“
“,” DisPaySchedulePrefix“:”“,” NextFreeIssueNo“:” 1“,” NextReturnNo“:” 20“,” UploadedType“:” 1“,” DisNextFreeIssueNo“:” 1“,” DisNextFOCNo“:” 1“,” NextVisitNo“:” 15“,” DisNextOrderNo“:” 1“,” UploadedOn“:” Jun
2011年17日
6:33 PM“,” NextReturnAcceptNo“:” 1“,” BusinessUnit“:” HEMA“,” TXNReferencePrefix“:” 20110708
“,” OrderPrefix“:” OR4“,” UploadedMethod“:” 3“,” FOCPrefix“:”
“,” ReturnPrefix“:” RT4
“,” RetailerPrefix“:” TEM4“,” NextRetailerNo“:” 10“,” NextInvoiceNo“:” 1“,” NextGRNNo“:” 1“,” InvoicePrefix“:” IN4
“,” NextTXNReference“:” 2“,” NextOrderNo“:” 37“,” ReturnAcceptPrefix“:”
“,” PaySchedulePrefix“:” PS4“,” NextReceiptNo“:” 1“,” NextFOCNo“:” 20“,” NextPayScheduleNo“:” 41“,” NextGRONo“:” 1“,” DisReturnPrefix“:”
“,” DisReceiptPrefix“:”“,” DisNextReturnNo“:” 1“,” DisOrderPrefix“:”
“,” DisNextReceiptNo“:” 1“,” DisNextPayScheduleNo“:” 1“,” NextActivityNo“:” 1“,” DisInvoicePrefix“:”
“,” DisNextInvoiceNo“:” 1“,” UploadedBy“:” WAT2“,” DisFreeIssuePrefix“:”
“,” DisFOCPrefix“:”“,” ReceiptPrefix“:” RP4“}
我在列表中使用了vaue和名称:
我这样写:
try {
// getSoapResponseTableDataJson(responsePrimitiveData,
// null,tablesName.get(i));
String result = responsePrimitiveData.toString();
JSONObject jsonobject = new JSONObject(result);
ArrayList<String> toFieldList = new ArrayList<String>();
ArrayList<String> toFieldValList = new ArrayList<String>();
JSONArray array = jsonobject.getJSONArray("Table1");
int max = array.length();
HashMap<String, String> applicationSettings = new HashMap<String, String>();
for (int j = 0; j < max; j++) {
System.out.println(" -- array.getJSONObject(j) -- "
+ array.getJSONObject(j));
String value = array.getJSONObject(j).getString("value");
String name = array.getJSONObject(j).getString("name");
applicationSettings.put(name, value);
}
System.out.println(" ---- json --- "+ applicationSettings);
} catch (JSONException e) {
e.printStackTrace();
}
这是说:
org.json.JSONException:没有价值
什么是名称和价值?
实际上,我想在单独的列表中获取键单独的列表和值对。
我想这样
名称,例如:
{ExecutiveCode,FreeIssuePrefix,DisPaySchedulePrefix,.....}
值:
{WAT2, "","TEst",.....}
请帮我。
提前致谢....
最佳答案
只是想想... JSON中没有{"name": "something"}
...
编辑...我读错了JSONObject文档...没有JSONObject.getNames()
使用obj.names()
JSONObject obj = array.getJSONObject(j);
JSONArray[] names = obj.names();
重复名称
String name = names.getString(i);
String value = obj.getString(name);
applicationSettings.put(name, value)
旧的答案是:
采用:
JSONObject obj = array.getJSONObject(j);
String[] names = JSONObject.getNames(obj);
重复名称
value = obj.getString(names[i])
关于android - Android Json结果处理,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6872396/