问题描述
我有JSON结果是这样的:array.getJSONObject(J) -
I have Json result like this: array.getJSONObject(j) --
{执行code:WAT2,FreeIssue preFIX:结果
\",\"DisPaySchedule$p$pfix\":\"\",\"NextFreeIssueNo\":\"1\",\"NextReturnNo\":\"20\",\"UploadedType\":\"1\",\"DisNextFreeIssueNo\":\"1\",\"DisNextFOCNo\":\"1\",\"NextVisitNo\":\"15\",\"DisNextOrderNo\":\"1\",\"UploadedOn\":\"Jun
17 2011
下午6点33分,NextReturnAcceptNo:1,BusinessUnit:HEMA,TXNReference preFIX:20110708
,订单preFIX:OR 4,UploadedMethod:3,FOC preFIX:搜索
,返回preFIX:RT4
\",\"Retailer$p$pfix\":\"TEM4\",\"NextRetailerNo\":\"10\",\"NextInvoiceNo\":\"1\",\"NextGRNNo\":\"1\",\"Invoice$p$pfix\":\"IN4
,NextTXNReference:2,NextOrderNo:37,ReturnAccept preFIX:搜索
\",\"PaySchedule$p$pfix\":\"PS4\",\"NextReceiptNo\":\"1\",\"NextFOCNo\":\"20\",\"NextPayScheduleNo\":\"41\",\"NextGRONo\":\"1\",\"DisReturn$p$pfix\":\"
,DisReceipt preFIX:,DisNextReturnNo:1,病症preFIX:搜索
,DisNextReceiptNo:1,DisNextPayScheduleNo:1,NextActivityNo:1,DisInvoice preFIX:
,DisNextInvoiceNo:1,UploadedBy:WAT2,DisFreeIssue preFIX:搜索
,DisFOC preFIX:,收据preFIX:RP4}
和我有拿vaue&安培;命名列表中的
And I have take vaue & name in the list:
我已经这样写的:
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:对于价值不价值
什么名字&安培;值?
what is name & value?
其实我想拿到钥匙单独的列表和放大器;值对在单独的列表....
我想利用这样的
名称,如: {执行code,FreeIssue preFIX,DisPaySchedule preFIX,......}
像值: {WAT2,,测试,...}
Actually I want to get the Key separate list & value pair in separate list....I want to take like this name like : {ExecutiveCode,FreeIssuePrefix,DisPaySchedulePrefix,.....}
value like : {WAT2, "","TEst",.....}
请帮我。
在此先感谢....
推荐答案
只是觉得......没有 {名:东西}
在你的JSON ...
just think ... there is no {"name": "something"}
in your JSON ...
修改 ...我念错的JSONObject文档... ...有没有JSONObject.getNames()
EDIT ... i read wrong JSONObject documentation ... there is no JSONObject.getNames()
使用obj.names()
use 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的JSON结果处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!