Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.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 解析IMDB-API JSON_Java_Json - Fatal编程技术网

Java 解析IMDB-API JSON

Java 解析IMDB-API JSON,java,json,Java,Json,我试图使用JSON简单库解析(示例:)提供的JSON电影信息,但没有成功。我不断收到错误,org.json.simple.JSONObject无法转换为org.json.simple.JSONArray 看看这个网站和休息时,我不明白为什么它不能解析信息。我正在使用下面提供的标准示例,但没有成功。如果您有任何帮助或其他JSON库可以使用,我们将不胜感激 这是我从网站上得到的字符串: JSONParser parser=new JSONParser(); Object obj = parser.p

我试图使用JSON简单库解析(示例:)提供的JSON电影信息,但没有成功。我不断收到错误,org.json.simple.JSONObject无法转换为org.json.simple.JSONArray

看看这个网站和休息时,我不明白为什么它不能解析信息。我正在使用下面提供的标准示例,但没有成功。如果您有任何帮助或其他JSON库可以使用,我们将不胜感激

这是我从网站上得到的字符串:

JSONParser parser=new JSONParser();
Object obj = parser.parse(s);
JSONArray array = (JSONArray)obj;

从API检索的JSON是

{"Search":[{"Title":"The Lord of the Rings: The Fellowship of the Ring","Year":"2001","imdbID":"tt0120737","Type":"movie"},{"Title":"The Lord of the Rings: The Return of the King","Year":"2003","imdbID":"tt0167260","Type":"movie"},{"Title":"The Lord of the Rings: The Two Towers","Year":"2002","imdbID":"tt0167261","Type":"movie"},{"Title":"The Lord of the Rings","Year":"1978","imdbID":"tt0077869","Type":"movie"},{"Title":"The Lord of the Rings: The Two Towers","Year":"2002","imdbID":"tt0347436","Type":"game"},{"Title":"The Lord of the Rings: The Return of the King","Year":"2003","imdbID":"tt0387360","Type":"game"},{"Title":"The Lord of the Rings: The Battle for Middle-Earth","Year":"2004","imdbID":"tt0412935","Type":"game"},{"Title":"Lord of the Rings: Battle for Middle Earth II - Rise of the Witch King","Year":"2006","imdbID":"tt1058040","Type":"game"},{"Title":"The Lord of the Rings: The Battle for Middle-Earth II","Year":"2006","imdbID":"tt0760172","Type":"game"},{"Title":"The Lord of the Rings: The Third Age","Year":"2004","imdbID":"tt0415947","Type":"game"}]}
它以
{
开头,这是一个JSON对象(
JSONObject
),而不是数组(
JSONArray

Object obj
的动态类型将是
JSONObject
,不能转换为
JSONArray

Object obj = parser.parse(s);
如果需要内部数组,请使用
JSONObject
get()
方法之一,键为
“Search”