0

I'm trying to read a json url

My Code:

// Creating JSON Parser instance
JSONParser jParser = new JSONParser();

// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);

If I execute my Code i'm not able to get String from URL

Here is my LogCat Error:

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

Could anyone help?

4

3 回答 3

2

您从 URL 获得的值是 JSONArray 而不是 JSONOBject。(这就是方括号的意思)。尝试这个:

JSONArray json = jParser.getJSONFromUrl(url);
JSONObject firstObject = json.getJSONObject(0);
JSONObject secondObject = json.getJSONObject(1);
...etc
于 2013-06-04T11:56:37.627 回答
0

线索在异常的末尾:... of type org.json.JSONArray cannot be converted to JSONObject. 给定 URL 处的 JSON 是有效的 JSON,但格式为 a JSONArray,而不是 a JSONObject

尝试将线路更改为JSONArray json = jParser.getJSONFromUrl(url);,它应该可以工作。

于 2013-06-04T11:55:34.120 回答
0

那是因为JSONArray不是JSONObject.

JSONArray仅扩展java.lang.Object

JSONArray 类的签名是:

public class org.json.JSONArray { 
     ... class body  ...
}
于 2013-06-04T11:53:15.213 回答