我正在尝试阅读json网址
我的代码:
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
如果我执行我的代码,我无法从URL获取字符串
这是我的LogCat错误:
06-04 17:13:45.162: E/JSON Parser(15988): Error parsing data org.json.JSONException: Value ["<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12036'>SPICE JET Recruits Freshers Data Entry Operator in Gurgaon<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12035'>TOSHIBA Freshers off Campus Drive Trainee Engineers in Bangalore <\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12034'>EMC Corporation Recruits Fresher Jobs Technical Support Engineers in bangalore<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12033'>AON Hewitt Freshers Walk in Drive 4th to 8th June in Chennai<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12032'>APPLIED MATERIALS Recruits Fresher Jobs Software Engineer on June in Bangalore<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12031'>US TECH Solutions Recruits Off-Campus Drive: Trainee on 14th June in Panipat<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12030'>SURPRISE SOLUTIONS Fresher Walk-in Software Engineer on 5th to 15th June in Chennai <\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12029'>MPHASIS Freshers Walk-in: Associate\/Senior Associate on 4th & 5th June in Bangalore<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12028'>ARROWSOFTWARE Technologies Recruits MBA Jobs: HR Last Date: 10th June in Hyderabad<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12027'>NUA TRANS MEDIA Fresher Walk-in: Trainee - Developer On 5th to 7th June in Chennai<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12026'>PCS Technology Recruits IT Helpdesk \/ Call Co Coordinator in Chennai<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12025'>ICICI Bank Recruits Bank Jobs Chartered Accountants<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12024'>BIOCON Recruits Engineering Jobs Executive\/ Jr Executive<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12023'>INTEL Technology Recruits Engineering Jobs Research Intern<\/a><br><br><br>","<a href='http:\/\/freshersadda.com\/jsonFeed\/faJsonFeedDetails.php?jid=12022'>SUTHERLAND global Recruits Healthcare Jobs Medical Coder <\/a><br><br><br>"] of type org.json.JSONArray cannot be converted to JSONObject
有人可以帮忙吗?
答案 0 :(得分:2)
您从URL获取的值是JSONArray而不是JSONOBject。 (那是方括号的意思)。试试这个:
JSONArray json = jParser.getJSONFromUrl(url);
JSONObject firstObject = json.getJSONObject(0);
JSONObject secondObject = json.getJSONObject(1);
...etc
答案 1 :(得分:0)
那是因为JSONArray
不是JSONObject
的孩子。
JSONArray
仅展开java.lang.Object
。
JSONArray类的签名是:
public class org.json.JSONArray {
... class body ...
}
答案 2 :(得分:0)
线索在异常结束时:... of type org.json.JSONArray cannot be converted to JSONObject
。给定网址的JSON是有效的JSON,但格式为JSONArray
,而不是JSONObject
。
尝试将该行更改为JSONArray json = jParser.getJSONFromUrl(url);
,它应该有效。