Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JSON解析对象中的Android-object_Java_Android_Parsing_Android Json - Fatal编程技术网

Java JSON解析对象中的Android-object

Java JSON解析对象中的Android-object,java,android,parsing,android-json,Java,Android,Parsing,Android Json,如何解析这个json?我想从title、field\u place和brothers字段中获取数据 { "events": [ { "event": { "title": "BITUMIX Martyna Jastrz\u0119bska", "field_place": "Nowe Miejsce Al Jerozolimskie 51 lok.2", "field_zdjecie": "http:\/\/wybierzkulture.waw.pl\/sites\/

如何解析这个json?我想从title、field\u place和brothers字段中获取数据

{
"events": [
{
  "event": {
    "title": "BITUMIX Martyna Jastrz\u0119bska",
    "field_place": "Nowe Miejsce Al Jerozolimskie 51 lok.2",
    "field_zdjecie": "http:\/\/wybierzkulture.waw.pl\/sites\/default\/files\/styles\/post\/public\/martyna_jastrzebska_bitumix_2.jpg?itok=nd2O5U5z"
  }
},
{
  "event": {
    "title": "Wiecz\u00f3r Komedii Improwizowanej - D\u017cem Impro!",
    "field_place": "",
    "field_zdjecie": "http:\/\/wybierzkulture.waw.pl\/sites\/default\/files\/styles\/post\/public\/dzem_17_maja.jpg?itok=bfgDYxKq"
  }
}, 
...
我试过:

JSONObject itemm = jArray.getJSONObject(i);
JSONObject oneObject = itemm.getJSONObject("event");
String title = oneObject.getString("title");
String field_place = oneObject.getString("field_place");
。。。但是它不起作用。

试试这个

JSONArray  element = jsonobj.getJSONArray("events");
              for(int i=0;i < element.length();i++){    
                    JSONObject e = element.getJSONObject(i);


                    Log.d("TESTTT22",e.getJSONObject("event").getString("title"));

              }


        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
JSONArray元素=jsonobj.getJSONArray(“事件”);
对于(inti=0;i
在JSON字符串中,有两个符号可以引导您完成解析:

{-表示JSONObject

[-表示JSONArray

解析json字符串时,您应该反复检查这些项目。要了解字符串中有多少JSONObject和JSONArray,以及应该从中开始解析,请使用json可视化工具,如::

示例:如您所见,根对象是一个JSONObject,它由一个JSONArray和三个JSONObject组成。要解析这种结构,您可以使用:

JSONObject jsonobj = new JSONObject(jsonstring);

String result = jsonObject.getString("success");
String error_number = jsonObject.getString("error_number");    
String error_message = jsonObject.getString("error_message"); 

JSON Array jsonarray = jsonobj.getJSONArray();

String[] names = new String[jsonArray.length()];    
String[] formattedNames = new String[jsonArray.length()];  

for(int i=0;i<jsonArray.length();i++)
{
    JSONObject jsonObject = jsonArray.getJSONObject(i);

    names [i] = jsonObject.getString("name");
    formattedNames [i] = jsonObject.getString("formattedName");
  }
JSONObject jsonobj=新的JSONObject(jsonstring);
字符串结果=jsonObject.getString(“成功”);
字符串错误号=jsonObject.getString(“错误号”);
字符串错误消息=jsonObject.getString(“错误消息”);
JSON数组jsonarray=jsonobj.getJSONArray();
字符串[]名称=新字符串[jsonArray.length()];
String[]formattedNames=新字符串[jsonArray.length()];

对于(int i=0;i什么是
它不起作用
意味着什么?另外,你看过什么是JSON吗?JSON格式支持什么?它意味着Android显示错误:System.err﹕ org.json.JSONException:title没有值,这说明了什么?根据您向我们展示的内容,您似乎有一个
事件
,没有
标题。为什么不使用Gson或Jackson呢?