How do I separate key value pair from Json String

2.3k views Asked by At

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
        }
    ]
}]
1

There are 1 answers

0
Mohammad Ashfaq On

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.