我有来自 bbc 的这种格式的 json 提要
{
"name": "ticker",
"entries": [
{
"headline": "text",
"prompt": "LATEST",
"isBreaking": "false",
"mediaType": "Standard",
"url": ""
},
{
"headline": "text",
"prompt": "LATEST",
"isBreaking": "false",
"mediaType": "Standard",
"url": ""
},
etc...........
我的代码如下:
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
JSONObject json = JSONfunctions.getJSONfromURL("http:/......");
try{
JSONArray item = json.getJSONArray("entries");
for (int i = 0; i<item.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = item.getJSONObject(i);
JSONObject title = e.JSONObject("headline");
map.put("title", "Title:" + e.getString("headline");
}
}
它给了我错误"java.lang.String cannot be converted to JSONObject"
我也试过省略JSONObject title = e.JSONObject("headline");
,它给了我一个路径错误(注意