-2

我有 json 文件。我在Android平台上很新。那么,请你们提供代码示例或示例。所以,我可以理解 json 解析。我尝试了很多例子。但是,它没有多大帮助。

[
    {
        "date": "12.09.2012",
        "events": 
        [
            {
                "time": "12:30",
                "type": "food",
                "title": "Lunch",
                 "type_id" : "1"
            },
            {
                "time": "14:00",
                "type": "session",
                 "type_id" : "0",
                "title": "Opening and Presentation of the Awards",
                "events": [
                    {
                        "time": "14:00",
                        "type": "general",
                        "type_id" : "3",
                        "title": "Opening (Local Organizers)"
                    },
                    {
                        "time": "14:05",
                        "type": "general",
                        "type_id" : "3",
                        "title": "Welcome TUM and LMU"
                    },
                    {
                        "time": "14:15",
                        "type": "general",
                        "type_id" : "2",
                        "title": "Welcome BMBF and Presentation of the Bernstein Award 2012",
                        "info": "Welcome BMBF and Presentation of the Bernstein Award 2012.Since 2006, the Federal Ministry of Education and Research (Bundesministerium für Bildung und Forschung, BMBF) annually confers the Bernstein Award for Computational Neuroscience to one excellent junior researcher with outstanding ideas for new research projects. The award is endowed with up to 1.25 million € over the course of five years and is one of the most highly remunerated research awards for young scientists in Germany. With this funding, the awardees can establish their own, independent research group at a research institution of their choice in Germany.\nThe Bernstein Awardee 2012 will be publicly announced within the opening session of the Bernstein Conference 2012, on September 12, 2012. Following the award ceremony, the awardee will present his/her current research and future projects to be conducted with the support of the award."
                    },
                    {
                        "time": "14:25",
                        "type": "general",
                        "type_id" : "3",
                        "title": "Lecture by the Bernstein Award Winner"
                    },
                    {
                        "time": "15:05",
                        "type": "general",
                        "type_id" : "2",
                        "title": "Presentation of the Braitenberg Award 2012",
                        "info": "Valentino Braitenberg Award – The Golden Neuron 2012.In honor of Prof. Valentino Braitenberg, one of the founding directors of the Max Planck Institute for Biological Cybernetics in Tübingen, and pioneer of Computational Neuroscience in Germany, who sadly passed away in September 2011, the Valentino Braitenberg Award was created. It will be awarded for the first time during the opening session of the Bernstein Conference on September 12, 2012.The prize recognizes outstanding researchers who have provided major contributions to our understanding of brain function and who significantly influenced brain research or are expected to do so. Especially considered are studies of the microscopic properties of brain architecture and their functional implications.The Award 2012 will go to Prof. Moshe Abeles from the Gonda Multidisciplinary Brain Research Center at Bar Ilan University, Israel."
                    },
                    {
                        "time": "15:10",
                        "type": "general",
                        "type_id" : "3",
                        "title": "Lecture by the Braitenberg Award Winner"
                    }
                ]
            },
            {
                "time": "15:50",
                "type": "food",
                "title": "Coffee",
                "type_id" : "1"
            },
            {
                "time": "16:20",
                "type": "session",
                "type_id" : "0",
                "title": "Neural Circuits: Structure and Signals",
                "events": [
                    {
                        "time": "16:20",
                        "type": "talk",
                        "type_id" : "3",
                        "title": "Structural Neurobiology: Tools for the dense reconstruction of neuronal circuits",
                        "person": "Moritz Helmstaedter (MPI Neurobiology Munich)",
                        "id": 65537
                    },
                    {
                        "time": "17:00",
                        "type": "talk",
                        "type_id" : "3",
                        "title": "How local is the local field potential?",
                        "person": "Gaute Einevoll (Aas)",
                        "id": 65538
                    }
                ]
            },
            {
                "time": "19:00",
                "type": "dinner",
                "type_id" : "1",
                "title": "Joint INCF/BCCN Conference Dinner",
                "location": "Münchner Künstlerhaus",
                "info": "Joint INCF / Bernstein Conference Dinner.The Joint Dinner will provide ample opportunities to meet with participants from both the INCF Congress and the Bernstein Conference at the “Münchner Künstlerhaus”. For more than a century, the ’Munich House of Artists’ has served as a gorgeous meeting place for artists and the general society alike. Participants will learn more about this historical gem over a welcome drink, after which a buffet-style dinner and beverages will be served. We look forward to a nice late-summer evening and stimulating discussions.The Joint INCF/Bernstein Conference Dinner will take place at the “Münchner Künstlerhaus am Lenbachplatz”, Wednesday, Sep 12, starting 19:00. It will take ca. 15 min from the conference venue to get there. Directions: From ‘Max-Weber-Platz’ take U4 (direction ’Westendstrasse’) or U5 (di- rection ’Laimer Platz’) to ’Karlsplatz (Stachus)’. Follow the signs ’Ausgang Lenbachplatz/ Karl- splatz/ Maxburgstraße’. Outside, turn right and cross the street. You will find the Künstlerhaus at the corner of Maxburgstrasse and Herzog-Max- Strasse. Take the entrance on Maxburgstrasse into the courtyard of the Künstlerhaus."
            }
        ]
    },
    {
        "date": "13.09.2012",
        "events": [
            {
                "time": "9:00",
                "type": "session",
                "type_id" : "0",
                "title": "Coding",
                "events": [
                    {
                        "time": "9:00",
                        "type": "talk",
                        "type_id" : "2",
                        "title": "Not noisy, just wrong: the computational and neural cause of behavioral variability",
                        "person": "Alexandre Pouget (Geneva)",
                        "id": 65539
                    },
                    {
                        "time": "9:40",
                        "type": "talk",
                        "type_id" : "2",
                        "title": "Neural computations underlying optimal multisensory cue integration",
                        "person": "Greg DeAngelis (Rochester)",
                        "id": 65540
                    }
                ]
            },
            {
                "time": "10:20",
                "type": "food",
                "type_id" : "1",
                "title": "Coffee"
            },
            {
                "time": "10:50",
                "type": "session",
                "type_id" : "0",
                "title": "Vision",
                "events": [
                    {
                        "time": "10:50",
                        "type": "talk",
                        "type_id" : "2",
                        "title": "Wakefulness, locomotion, and navigation: A look from visual cortex",
                        "person": "Matteo Carandini (UCL London)",
                        "fontid": "31641",
                        "id": 65541
                    },
                    {
                        "time": "11:30",
                        "type": "talk",
                         "type_id" : "3",
                        "title": "Temporal constraints for visual object recognition:  neurophysiological, behavioural and computational approaches",
                        "person": "Gabriel Kreiman (Harvard)",
                        "id": 65542
                    },
                    {
                        "time": "12:10",
                        "type": "talk",
                         "type_id" : "2",
                        "title": "A sketch of a theory of visual cortex",
                        "person": "Tomaso Poggio (MIT)",
                        "id": 66543
                    }
                ]
            },
            {
                "time": "12:50",
                "type": "food",
                 "type_id" : "1",
                "title": "Lunch"
            },
            {
                "time": "14:00",
                "type": "session",
                 "type_id" : "0",
                "title": "Network Dynamics and Representations",
                "events": [
                    {
                        "time": "14:00",
                        "type": "talk",
                        "type_id" : "3",
                        "title": "Neurogrid: Simulating a million neurons and a billion synapses in real-time with sixteen neuromorphic chips",
                        "person": "Kwabena Boahen (Stanford)",
                        "frontid": "31702",
                        "id": 65544
                    },
                    {
                        "time": "14:40",
                        "type": "talk",
                        "type_id" : "3",
                        "title": "Overcomplete representations and neuronal circuit dynamics",
                        "person": "Shaul Druckmann (Janelia Farm)",
                        "id": 65545
                    }
                ]
            },
            {
                "time": "15:20",
                "type": "food",
                "type_id" : "1",
                "title": "Coffee"
            },
            {
                "time": "15:50",
                "type": "session",
                "type_id" : "0",
                "title": "Learning",
                "events": [
                    {
                        "time": "15:50",
                        "type": "talk",
                        "type_id" : "3",
                        "title": "Statistical and causal learning",
                        "person": "Bernhard Schölkopf (MPI Tübingen)",
                        "frontid": "31665",
                        "id": 65546
                    },
                    {
                        "time": "16:30",
                        "type": "talk",
                         "type_id" : "3",
                        "title": "Internal models: of ferret and men",
                        "person": "Máté Lengyel (Cambridge)",
                        "id": 65547
                    },
                    {
                        "time": "17:10",
                        "type": "talk",
                         "type_id" : "3",
                        "title": "Self-organization and unsupervised learning in recurrent networks",
                        "person": "Jochen Triesch (FIAS Frankfurt)",
                        "fontid": "31654",
                        "id": 65548
                    }
                ]
            },
            {
                "time": "18:00",
                "type": "poster",
                 "type_id" : "1",
                "title": "Poster Session I"
            },
            {
                "time": "20:00",
                "type": "talk",
                 "type_id" : "3",
                "title": "Public evening lecture",
                "events": [
                    {
                        "time": "20:00",
                        "type": "lecture",
                         "type_id" : "2",
                        "title": "Intelligenz ohne Hirnrinde? Wie Vögel einen eigenen Weg zu kognitiven Höchstleistungen gefunden haben",
                        "person": "Onur Güntürkün (Bochum)",
                        "info": "Public Bernstein Lecture 2012.The Bernstein Conference touches upon many themes that are of high public interest, from fundamental questions about brain and mind to clinical and biotechnological applications of neuroscience research. To foster the exchange between computational neuroscientists and the interested public and to provide an overview about a specific research topic that is at the focus of research within the Bernstein Network, the Public Bernstein Lecture has been introduced in 2012. To reach a broad audience, the lecture will be given in German, at 20:00 on September 13, 2012.This year’s speaker is Prof. Onur Güntürkün from Ruhr-Universität Bochum. He will talk about the astounding cognitive abilities of birds. Complex thinking without a cortex - certainly a thought-provoking topic."
                    }
                ]
            }
        ]
    }
]
4

3 回答 3

1

[表示 json 数组节点。

{表示 jsonobject 节点。

例子:

   JSONArray myListsAll= new JSONArray(myjsonstring);// json array
   JSONObject jsonobject= (JSONObject) myListsAll.get(0); // index 0
   JSONArray json = new JSONArray(jsonobject.getString("events")); // list events
             for(int i=0;i<json.length();i++)
             {
             JSONObject jsonObject1 = (JSONObject) json.get(i);  //
             String time= jsonObject1.getString("time");
             String type= jsonObject1.getString("type"); 
             String title= jsonObject1.getString("title");
             String id= jsonObject1.getString("type_id");
             System.out.println("time="+time);
             System.out.println("type="+type);
             System.out.println("title="+title);
             System.out.println("id="+id);
             }    

输出 :

date=12.09.2012

 time=12:30

 type=food

 title=Lunch

 id=1

 time=14:00

 type=session

 title=Opening and Presentation of the Awards

 id=0

 time=15:50

 type=food

 title=Coffee

 id=1

 time=16:20

 type=session

 title=Neural Circuits: Structure and Signals

 id=0

 time=19:00

 type=dinner

 title=Joint INCF/BCCN Conference Dinner

 id=1
于 2013-06-22T05:38:04.267 回答
0

获得 JSON 字符串后,您可以简单地使用JSONOject. 下面的示例使用 Instagram 数据...

        JSONObject jsonObject = new JSONObject(dataAsString);

        //grab data to return
        results = jsonObject.getJSONArray("data");

        mTagMapping.put(tag, jsonObject.getJSONObject("pagination").optString("next_url") + "&count=" + COUNT);
于 2013-06-22T05:11:55.160 回答
0

创建一个 JSONObject:

JSONObject jObject = new JSONObject(result);

获取特定字符串:

String aJsonString = jObject.getString("name");

要获取特定的 JSONArray:

JSONArray jArray = jObject.getJSONArray("array");

要从数组中获取项目:

for (int i=0; i < jArray.length(); i++)
{
    try {
        JSONObject oneObject = jArray.getJSONObject(i);

        String oneObjectsItem = oneObject.getString("nameinarray");
        String oneObjectsItem2 = oneObject.getString("name2inarray");
    } catch (JSONException e) {

    }
}
于 2013-06-22T05:21:38.980 回答