Maclean Pinto
Maclean Pinto

Reputation: 1135

How to parse a json using GSON

Below is the json response i am getting from a external service.

{"userAttributeList": [  
    {"Name":"PROFILE.UUID","Value":”SL1-4XXXXX0"},  
    {"Name":"PROFILE.UserId","Value":"[email protected]"},  
    {"Name":"PROFILE.FirstName","Value":"John"},  
    {"Name":"PROFILE.LastName","Value":"Smith"},  
    {"Name":"PROFILE.EmailAddress","Value":"[email protected]"},  
    {"Name":"SETTING.COMMON.REGIONAL_SETTINGS.DATEFORMAT_DATEPATTERN","Value":"dddd d MMMM yyyy"},  
    {"Name":"SETTING.COMMON.REGIONAL_SETTINGS.DATEFORMAT_TIMEPATTERN","Value":"HH:mm:ss"},  
    {"Name":"SETTING.COMMON.REGIONAL_SETTINGS.DATEFORMAT_TIMEZONE","Value":"Romance Standard Time"}  
]}  

I am stil trying the figure out a way to deserialize this . Its not in nor form. Can any one suggest a way to go a head with this.

Upvotes: 1

Views: 86

Answers (2)

Shahjahan Khan
Shahjahan Khan

Reputation: 189

try {
    JSONArray response=new JSONArray(jsonstring);
    for (int i = 0; i < response.length(); i++) {
        JSONObject data=response.getJSONObject(i);
        String name=data.getString("Name");
        String values=data.getString("Values");
        //perform operation on name and values
    }
} catch (JSONException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

Upvotes: 1

ggmathur
ggmathur

Reputation: 843

It looks like you have an invalid character in here:

"Value": ”SL1-4XXXXX0"}
         ^

I suggest a) replacing ” with " and b) figuring out why you're getting that in the first place.

Tip: If you're not sure what's wrong with your JSON, check out JSONLint

Upvotes: 5

Related Questions