You need to sign in to do that
Don't have an account?
Arjun y 7
Need to pass json string
Hi All,
Our scenario is, we need to deserialize the below JSON structure using Rest API in salesforce.
String JSONString =
"[{
"Accounts":
{
"score":
{
"bghu": "1"
"ghdf": "/Date(14-5-2012)/"
"erty": "hjuyt"
"jgfhd": "30"
"poiu": " 0.00"
"nbvc": " 0.00"
"vjdt": " 200000.00"
"ghgh": " 200000.00"
"jkkj": " 100000.00-"
}
}
}]"
Rest Class
Map<String, object> root = (Map<String, object>)JSON.deserializeUntyped(jsonString);
I am receiving the value after deserializing the jsonstring
root = {d={results=({erty=ZTRD, ghgh=200000.00, vjdt=200000.00, bghu=1, poiu=0.00, jgfhd=30, nbvc=0.00, ghdf=/Date(1459123200000)/, jkkj=100000.00-})}}
Now i want results in a list in below format
List<Object> items = (List<Object>)root.get('results'); But while i am doing this, receiving result as null.
Can any one help me on this
Our scenario is, we need to deserialize the below JSON structure using Rest API in salesforce.
String JSONString =
"[{
"Accounts":
{
"score":
{
"bghu": "1"
"ghdf": "/Date(14-5-2012)/"
"erty": "hjuyt"
"jgfhd": "30"
"poiu": " 0.00"
"nbvc": " 0.00"
"vjdt": " 200000.00"
"ghgh": " 200000.00"
"jkkj": " 100000.00-"
}
}
}]"
Rest Class
Map<String, object> root = (Map<String, object>)JSON.deserializeUntyped(jsonString);
I am receiving the value after deserializing the jsonstring
root = {d={results=({erty=ZTRD, ghgh=200000.00, vjdt=200000.00, bghu=1, poiu=0.00, jgfhd=30, nbvc=0.00, ghdf=/Date(1459123200000)/, jkkj=100000.00-})}}
Now i want results in a list in below format
List<Object> items = (List<Object>)root.get('results'); But while i am doing this, receiving result as null.
Can any one help me on this
'results' is no the key for your map but rather 'd'.
If you want something more complex, you need to try the following:
http://salesforce.stackexchange.com/questions/27165/how-do-i-parse-a-json-map-into-an-apex-map
Sry, wrongly gave result in above. The correct one is List<Object> items = (List<Object>)root.get('score')
My JSON Structure is:
{
"Accounts":
{
"score":
{
"AAA": 0.1,
"BBB": 0.3, ..... } } For this i want to pass values in a list for score array only.
So, the only way you can get the values for score is through a series of chain events:
If you want an array of objects, your JSON should be in thhe following format:
....
"score" : ["myArray": {"AAA" : 0.1, ...}]
If you still want to keep your orignal JSON, you may need to parse it then:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_jsonparser.htm