You need to sign in to do that
Don't have an account?
JSON to Apex class
Hi,
I'm new to salesforce and don't know much about it. I would like to create apex classes for the following json string and deserialize it. can somebody help me to write the apex class? thank you..
{
"name" : {
"givenName" : "smith",
"familyName" : "peter",
"formatted" : "Smith Peter"
},
"location" : "london",
"type" : "person",
"displayName" : "smith peter",
"status" : "xyz gets recognized by industry analyst as a leader...",
"tags" : [ "leadership", "financial", "analysis", "capital", "formation", "contract", "talent", "management", "entrepreneur" ],
"published" : "2011-11-01T20:17:08.667+0000",
"followingCount" : 64,
"thumbnailUrl" : "https://xyz.com",
"jive" : {
"level" : {
"name" : "Contributor",
"description" : "",
"points" : 65
},
"timeZone" : "America/New_York",
"locale" : "en_US",
"username" : "psmith",
"profile" : [ {
"value" : "President & CEO",
"jive_label" : "Title"
}, {
"value" : "11/06/2011",
"jive_label" : "Join Date"
}, {
"value" : "lived in NY ",
"jive_label" : "Biography"
}, {
"value" : "",
"jive_label" : "Expertise"
}, {
"value" : [ "Financial Services ", "Business Services " ],
"jive_label" : "Industries"
}, {
"value" : [ "Finance ", "Business Development ", "Consulting ", "Business Analysis ", "Marketing " ],
"jive_label" : "Disciplines"
}, {
"value" : ".",
"jive_label" : "What do you do?"
}, {
"value" : "team.",
"jive_label" : "My Style"
}, {
"value" : "http://www.xyz.com",
"jive_label" : "Website"
}, {
"value" : "",
"jive_label" : "Business Manager"
}, {
"value" : "https://twitter.com/#!/x",
"jive_label" : "Twitter"
} ],
"external" : false,
"visible" : true,
"enabled" : true,
"externalContributor" : false,
"federated" : false
},
"updated" : "2013-11-12T04:57:20.140+0000",
"emails" : [ {
"value" : "xyz.com@localhost",
"type" : "work",
"jive_label" : "Email",
"primary" : true
} ],
"photos" : [ {
"value" : "https://xy.com"
} ],
"thumbnailId" : "1093",
"followerCount" : 50,
"resources" : {
"following" : {
"ref" : "xy.xom",
"allowed" : [ "GET" ]
},
"followers" : {
"ref" : "xy.com",
"allowed" : [ "GET" ]
},
"activity" : {
"ref" : "https://xys.com",
"allowed" : [ "GET" ]
}
},
"id" : "2010"
}
http://json2apex.herokuapp.com/ can do it for you.
Thanks Brian for your quick response. I'm getting this error message when I save the code:
Type cannot be constructed: String at "tags.add(new String(parser));"
here is the code from http://json2apex.herokuapp.com/
Hi,
Is there are any way to handle string value and list<string> value under the same class. Here I have to create a profile class which has string value and list<string> value for jive_label. Can someone help me to parse these variables pls?
{
"name" : {
"givenName" : "smith",
"familyName" : "peter",
"formatted" : "Smith Peter"
},
"location" : "london",
"type" : "person",
"displayName" : "smith peter",
"tags" : [ "leadership", "financial", "analysis", "capital", "formation", "contract", "talent", "management", "entrepreneur" ],
"jive" : {
"level" : {
"name" : "Contributor",
"description" : "",
"points" : 65
},
"timeZone" : "America/New_York",
"locale" : "en_US",
"username" : "psmith",
"profile" : [ {
"value" : "President & CEO",
"jive_label" : "Title"
}, {
"value" : "yes",
"jive_label" : "Expertise"
}, {
"value" : [ "Financial Services ", "Business Services " ],
"jive_label" : "Industries"
}, {
"value" : [ "Finance ", "Business Development ", "Consulting ", "Business Analysis ", "Marketing " ],
"jive_label" : "Disciplines"
}, {
"value" : ".",
"jive_label" : "What do you do?"
}, {
"value" : "http://www.facebook.com/x",
"jive_label" : "Facebook"
} ],
"federated" : false
},
"id" : "2010"
}
Try not using the "generate explict parse code" option.