小编典典

如何在Android中解析JSON字符串?

json

我正在从服务器获取JSON字符串,并且已经通过代码获取了JSON字符串。但是我不知道如何解析它。

以下是我的JSON字符串

{
    "university": {
        "name": "oxford",
        "url": "http://www.youtube.com"
    },
    "1": {
        "id": "2",
        "title": "Baseball",
        "datetime": "2011-11-11 10:41:46"
    },
    "2": {
        "id": "1",
        "title": "Two basketball team players earn all state honors",
        "datetime": "2011-11-11 10:40:57"
    }
}

请提供任何指导或代码段。


阅读 273

收藏
2020-07-27

共1个答案

小编典典

使用JSON类进行解析,例如

JSONObject mainObject = new JSONObject(Your_Sring_data);
JSONObject uniObject = mainObject.getJSONObject("university");
String  uniName = uniObject.getString("name");
String uniURL = uniObject.getString("url");

JSONObject oneObject = mainObject.getJSONObject("1");
String id = oneObject.getString("id");
....
2020-07-27