Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.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
JSON解析(未找到JSON对象)Java_Java_Arrays_Json_Jsonobject - Fatal编程技术网

JSON解析(未找到JSON对象)Java

JSON解析(未找到JSON对象)Java,java,arrays,json,jsonobject,Java,Arrays,Json,Jsonobject,我有一个JSON文件格式,在一个名为“JSON”的变量中,我想要解析它。 但是,我收到以下错误消息: Exception in thread "main" org.json.JSONException: JSONObject["bindings"] not found. 这是我正在使用的代码: JSONObject obj = new JSONObject(json); JSONArray bindings = obj.getJSONArray("bindings")

我有一个JSON文件格式,在一个名为“JSON”的变量中,我想要解析它。 但是,我收到以下错误消息:

Exception in thread "main" org.json.JSONException: JSONObject["bindings"] not found.
这是我正在使用的代码:

JSONObject obj =  new JSONObject(json);            
JSONArray bindings = obj.getJSONArray("bindings");       

for (int i=0; i<obj.length(); i++)
{
JSONObject x = bindings.getJSONObject(i);                
x.getJSONObject("type1").getString("type");  
System.out.println(x);
}
即使我在没有for循环的情况下执行以下操作,它也会显示相同的错误消息

JSONObject obj =  new JSONObject(json);            
JSONArray bindings = obj.getJSONArray("bindings");  

您需要先通过结果
JSONObject
,才能到达
JSONArray

JSONObject obj =  new JSONObject(json);           
JSONObject results = obj.getJSONObject("results"); 
JSONArray bindings = results.getJSONArray("bindings");     
JSONObject obj =  new JSONObject(json);           
JSONObject results = obj.getJSONObject("results"); 
JSONArray bindings = results.getJSONArray("bindings");