KZoNE
KZoNE

Reputation: 1329

How do I separate key value pair from Json String

I want to take data from Json file to populate custom list in android. How do I take out all key value pairs from following json string. I'm new to android/Json and Sorry about my English. Please help me.

[{
    "profile": {
        "userID": 11,
        "username": "manvir1",
        "name": "Manvir Singh",
        "avatar": "manvir1/profile.jpg",
        "rank": 3009,
        "type": "consumer",
        "email": "[email protected]",
        "location": "Melaka, MY"
    },
    "malls": [{
            "mallID": 57,
            "mall": "Mid Valley",
        },

        {
            "mallID": 19,
            "mall": "Nu Sentral",
        }
    ]
    "redemption": [{
            "dealID": 5177,
            "company": "Rodeology",
            "deal": "nostrud exercitation officia est in",
            "price": 691,
            "percentage": 57
        },

        {
            "dealID": 1369,
            "company": "Navir",
            "deal": "ullamco irure aliqua qui eu",
            "price": 74,
            "percentage": 20
        }, {
            "dealID": 5182,
            "company": "Interodeo",
            "deal": "eiusmod ullamco cupidatat sit nostrud",
            "price": 546,
            "percentage": 4
        }
    ]
}]

Upvotes: 0

Views: 2347

Answers (1)

Mohammad Ashfaq
Mohammad Ashfaq

Reputation: 1375

Your string contains JSON array, so you have to parse it using JSONArray and not JSONObject. After that you have to get the JSONObject from JSONArray at position 0 which contains all the records like profile, mails and redemption.

Upvotes: 1

Related Questions