私はJSON
応答を得るアプリケーションに取り組んでいます。応答は次のとおりです。
[
{
"CID": 5,
"ChildMenus": [],
"Level": null,
"MenuUrl": "",
"Name": "Jewelry",
"PCID": 235,
"REnum": null,
"isLooseDiamond": "NO"
},
{
"CID": 122,
"ChildMenus": [],
"Level": null,
"MenuUrl": "",
"Name": "Collection",
"PCID": 235,
"REnum": null,
"isLooseDiamond": "NO"
},
{
"CID": 459,
"ChildMenus": [],
"Level": null,
"MenuUrl": "http://jewelry.roughdiamondxchange.in/Guide.aspx",
"Name": "Education",
"PCID": 235,
"REnum": null,
"isLooseDiamond": "NO"
},
{
"CID": 483,
"ChildMenus": [],
"Level": null,
"MenuUrl": "",
"Name": "Design Your Own ",
"PCID": 235,
"REnum": null,
"isLooseDiamond": "NO"
},
{
"CID": 486,
"ChildMenus": [],
"Level": null,
"MenuUrl": "http://jewelry.roughdiamondxchange.in/About.aspx",
"Name": "Policy",
"PCID": 235,
"REnum": null,
"isLooseDiamond": "NO"
},
{
"CID": 56,
"ChildMenus": [],
"Level": null,
"MenuUrl": "",
"Name": "Diamonds",
"PCID": 235,
"REnum": null,
"isLooseDiamond": "YES"
},
{
"CID": 611,
"ChildMenus": [],
"Level": null,
"MenuUrl": "",
"Name": "Overview",
"PCID": 235,
"REnum": null,
"isLooseDiamond": "NO"
}
]
これを解析するために、以下のコードを使用しました
try {
// Getting Array of Contacts
/*JSONObject jsonObject = new JSONObject(json);*/
/*JSONArray array = json.getJSONArray("Value");*/
JSONArray array=new JSONArray();
array.put(getJSONFromUrl());
// looping through All Contacts
for(int i = 0; i < array.length(); i++){
JSONObject c = array.getJSONObject(i);
/* JSONObject object = jsonObject.getJSONObject("FirstObject");*/
// Storing each json item in variable
/*String cid = c.getString(TAG_CID);*/
String name = c.getString(TAG_NAME);
String pcid = c.getString(TAG_PCID);
String menuurl = c.getString(TAG_MENUURL);
// Phone number is agin JSON Object
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
/* map.put(TAG_CID, cid);*/
map.put(TAG_NAME, name);
map.put(TAG_PCID, pcid);
map.put(TAG_MENUURL, menuurl);
// adding HashList to ArrayList
menuList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
エラーが発生しますorg.json.JSONException: No value for name
。データを解析できません。日付を解析する方法についてのアイデアをいただければ幸いです。