如何解析JSON字符串中的Andr​​oid?字符串、JSON、oid、Andr

2023-09-11 12:39:39 作者:触碰终极

可能重复:   在 JSON数组迭代的Andr​​oid / Java的

Possible Duplicate: JSON Array iteration in Android/Java

我获取来自服务器的JSON字符串,我已经得到了JSON字符串由code。 但我不知道如何分析它。

I am fetching JSON string from server and I have already got JSON string by code. But I didn't understand how to parse it.

下面是我的JSON字符串

Below is my JSON string

{
    "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"
    }
}

请提供任何指导或code段。

Please provide any guidance or code snippet.

推荐答案

使用JSON类解析如

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

JSONObject oneObject = mainObject.getJSONObject("1");
String id = oneObject.getJSONObject("id");
....