的Json問題:得到JSON結果中的Android
我已經這個格式化JSON
{
"Table1":[
{
"TableName":"LoadDistributor",
"Description":"Distributor ",
"MandatoryFlag":"1",
"Status":"",
"Priority":"0"
},
{
"TableName":"LoadPrice",
"Description":"Price ",
"MandatoryFlag":"1",
"Status":"",
"Priority":"0"
},
{
"TableName":"LoadProduct",
"Description":"Product ",
"MandatoryFlag":"1",
"Status":"",
"Priority":"0"
},
{
"TableName":"RD.AlternativeProductDetail",
"Description":"AltProdutDetail",
"MandatoryFlag":"0",
"Status":"",
"Priority":"0"
},
{
"TableName":"XA.vwTown",
"Description":"Town ",
"MandatoryFlag":"1",
"Status":"",
"Priority":"0"
}
] }
的Android的Json處理的方法是:
public String[] getStringArrayResponseJson(SoapPrimitive node, ArrayList<String> strings) {
try{
String result = node.toString();
JSONObject json = new JSONObject(result);
// Parsing
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
Log.i("@@@" , "===="+ valArray.length());
for (int i = 0; i < valArray.length(); i++) {
strings.add(valArray.getString(i));
}
json.put("sample key", "sample value");
Log.i("REST", "<jsonobject>\n" + json.toString()
+ "\n</jsonobject>");
}catch (JSONException e) {
e.printStackTrace();
}
我的要求是我想要將TableName轉換爲字符串[]或列表...我們如何做到這一點?
請幫助我在我的json處理方法中出現什麼錯誤:?
你想在一個字符串數組中的所有表名字段?只有這個領域? –
謝謝Pepi。是。需要獲取所有表名。根據David Olsson的回答,現在工作正常。 Thanx; – Piraba