首页
学习
活动
专区
圈层
工具
发布

解析IMDB
EN

Stack Overflow用户
提问于 2013-09-10 17:20:39
回答 1查看 1.1K关注 0票数 0

我试图使用JSON解析http://www.omdbapi.com (例如:http://www.omdbapi.com/?s=Lord%20Of%20the%20rings)提供的JSON电影信息,但没有成功。我一直得到org.json.simple.JSONObject不能转换为org.json.simple.JSONArray的错误。

看一看网站和休息,我不知道为什么它不能解析信息。我正在使用下面提供的标准示例,但没有成功。如果有任何帮助或替代的JSON库能够工作,我们将不胜感激。

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

代码语言:javascript
复制
JSONParser parser=new JSONParser();
Object obj = parser.parse(s);
JSONArray array = (JSONArray)obj;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-10 17:21:43

从API中检索的JSON是

代码语言:javascript
复制
{"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)。

代码语言:javascript
复制
Object obj = parser.parse(s);

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

如果您想要内部数组,请使用get()JSONObject方法之一,并使用键"Search"

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18725201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档