如何将JSONObject转换为JSONArray

时间:2014-11-23 20:22:52

标签: java android json

你能帮我解析一下这个JSON字符串吗?

[{"Id":"b8d2cd88-b042-46df-b82f-1ec29cc24760","Name":"Stedelijk Gymnasium Arnhem","Url":"https://sga.magister.net"}]

我从服务器检索此字符串并将其转换为JSONObject,但我无法访问Id,名称和URL,因此我想将其转换为JSONArray。我已经尝试过使用JSONSerializer和JSONParser(因为我在其他帖子的答案中找到了这些),但不知怎的,我无法导入这些类。你能帮我吗?

1 个答案:

答案 0 :(得分:2)

  

我从服务器检索此字符串并将其转换为JSONObject

返回的字符串为JSONArray而不是JSONObject,因此请将其转换为JSONArray,然后从中获取JSONObject

JSONArray jsonArr=new JSONArray("SERVER_STRING");
JSONObject jsonObj=jsonArr.getJSONObject(0);
// get all values from jsonobject using keys
 String strId=jsonObj.getString("Id");
 ....
相关问题