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
  • Your error is right there. have you checked if its returning a valid jSON? Commented Jun 4, 2013 at 11:52
  • can u share your code... Commented Jun 4, 2013 at 11:55
  • it is a JSONArray and not JSONObject. change it to JSONArray. try using Gson for parsing. Commented Jun 4, 2013 at 12:01
  • 1
    in your next response (when i clicked next url) is JSONArray of JSONArray which contain JSONObject. so its nested one so please parse accordingly. Commented Jun 4, 2013 at 12:02

3 Answers 3

2

The value you are getting from the URL is a JSONArray not a JSONOBject. (Thats what the square brackets mean). Try this:

JSONArray json = jParser.getJSONFromUrl(url);
JSONObject firstObject = json.getJSONObject(0);
JSONObject secondObject = json.getJSONObject(1);
...etc
Sign up to request clarification or add additional context in comments.

Comments

0

That's because JSONArray is not a child of JSONObject.

JSONArray extends java.lang.Object only.

The signature of JSONArray class is:

public class org.json.JSONArray { 
     ... class body  ...
}

Comments

0

The clue is at the end of the exception: ... of type org.json.JSONArray cannot be converted to JSONObject. The JSON at the given URL is valid JSON, but in the form of a JSONArray, not a JSONObject.

Try changing the line to JSONArray json = jParser.getJSONFromUrl(url); and it should work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.