question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Json Parsing error

See original GitHub issue

I need to parse this JSON with as minimum code as possible. How can i achieve this?

SAMPLE JSON -

{
  "count": 30,
  "recipes": [
    {
      "publisher": "Closet Cooking",
      "f2f_url": "http:\/\/food2fork.com\/view\/35382",
      "title": "Jalapeno Popper Grilled Cheese Sandwich",
      "source_url": "http:\/\/www.closetcooking.com\/2011\/04\/jalapeno-popper-grilled-cheese-sandwich.html",
      "recipe_id": "35382",
      "image_url": "http:\/\/static.food2fork.com\/Jalapeno2BPopper2BGrilled2BCheese2BSandwich2B12B500fd186186.jpg",
      "social_rank": 100,
      "publisher_url": "http:\/\/closetcooking.com"
    },
    {
      "publisher": "The Pioneer Woman",
      "f2f_url": "http:\/\/food2fork.com\/view\/47024",
      "title": "Perfect Iced Coffee",
      "source_url": "http:\/\/thepioneerwoman.com\/cooking\/2011\/06\/perfect-iced-coffee\/",
      "recipe_id": "47024",
      "image_url": "http:\/\/static.food2fork.com\/icedcoffee5766.jpg",
      "social_rank": 100,
      "publisher_url": "http:\/\/thepioneerwoman.com"
    },
   ]
}

I tried this -

AndroidNetworking.get(Constants.RECIPE_DUMMY_ENDPOINT)
               .setPriority(Priority.HIGH)
               .build()
               .getAsObjectList(Recipe.class, new ParsedRequestListener<List<Recipe>>() {
                   @Override
                   public void onResponse(List<Recipe> response) {
                       Log.i(TAG, "onResponse: "+response.size());
                       Log.i(TAG, "onResponse: "+response.get(0).toString());
                   }

                   @Override
                   public void onError(ANError anError) {
                       Log.e(TAG, "onError: "+anError.getErrorDetail() );

                   }
               });

It gives parsing error - E/MainActivity: onError: parseError The Recipe class contains all the getters,setters and parameterised constructor for each of the JSON objects inside the JSON array “responses”. Where am I going wrong?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
knightcubecommented, Sep 3, 2018

Great. That works. Thanks alot! Could you please add this small detail in the Readme? Would help everyone.

0reactions
knightcubecommented, Sep 3, 2018

Oh okay i got it. Will try that just now

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
How to handle invalid JSON parse error properly.
The most common way to handle JSON parse error is using try-catch block. If the JSON string is valid, it will return a...
Read more >
SyntaxError: JSON.parse: bad parsing Breaking Your Code ...
In JavaScript, when passing JSON to the JSON.parse() method, the method expects properly formatted JSON as the first argument. When it detects ...
Read more >
What Is JSON and How to Handle an “Unexpected Token” Error
In this article you will learn what JSON is and how you can deal with errors occurring when parsing JSON data, such as...
Read more >
SyntaxError: JSON.parse: bad parsing - DZone
SyntaxError is an inherited object of the main error object The main reason behind the error is usually a mistake in the JSON...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found