0

I am trying to send data from drupal website to android app in the form of json. i have created the link and now my link is returning data in this form. i don't have any idea how to parse this formatted data to show in a list view in android app.

{
  "nodes" : [
    {
      "node" : {
        "title" : "Saksham Iron Store",
        "Contact" : "09216630565",
        "Category" : "Decoration & Hardware",
        "City" : "Sangrur"
      }
    },
    {
      "node" : {
        "title" : "Loaffer Hut Garments",
        "Contact" : "8591697698",
        "Category" : "Fashion & Garments",
        "City" : "Sangrur"
      }
    },
    {
      "node" : {
        "title" : "BCB English Academy and Visa Guidance",
        "Contact" : "8699010091",
        "Category" : "Education",
        "City" : "Sangrur"
      }
    },
    {
      "node" : {
        "title" : "Aggarwal Engineering Corporation",
        "Contact" : "9417070197",
        "Category" : "Decoration & Hardware",
        "City" : "Sangrur"
      }
    },
    {
      "node" : {
        "title" : "Inder Sain Paint and Decoration",
        "Contact" : "9888821904",
        "Category" : "Decoration & Hardware",
        "City" : "Sangrur"
      }
    }
  ]
}

How can i parse it and show in listview in android app?

  • Your question should be "How to parse JSON in Android?" – Raptor Feb 11 '15 at 10:03
  • possible duplicate of [How to parse JSON in Android](http://stackoverflow.com/questions/9605913/how-to-parse-json-in-android) – Raptor Feb 11 '15 at 10:03
  • there is a difference in format [ { "vehicleType": "excavator", "vehicleColor": "yellow", "fuel": "diesel", "approvedOperators": [ { "name": "Greg Stark", "experiencePoints": 13 }, { "name": "Aarti Patel", "experiencePoints": 21 }, { "name": "Tarek Mizan", "experiencePoints": 9 } ], "treadType": "plate chain" }, "treadType": "wheel" } ] – Parveen Kumar Feb 11 '15 at 10:19
  • You should learn to adapt the changes instead of yelling the structure is different. Read up the API documentation. – Raptor Feb 11 '15 at 10:32

1 Answers1

0

Assuming that the JSON syntax of your receiving data conforms to the standard model you can parse JSON in android with one of the libraries already present in the org.json package (eg. JSONArray for arrays).

I'd suggest you take a look at GSON library ( my personal preference, there are of course many others) for it makes it easier to focus on your business logic and not occupy yourself with parsing JSON.

George Daramouskas
  • 3,720
  • 3
  • 22
  • 51