您从 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 = parser.parse(s);
Object obj
的动态类型将JSONObject
不能转换为JSONArray
.
如果您想要内部数组,请使用, 和 key的get()
方法之一。JSONObject
"Search"