+ Start a Discussion
Arjun y 7Arjun 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 = 
"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
Temoc MunozTemoc Munoz
Hi Arjun.

'results' is no the key for your map but rather 'd'.
List<Object> items = (List<Object>)root.get('d');

If you want something more complex, you need to try the following:
Arjun y 7Arjun y 7
Hi Temoc,

Sry, wrongly gave result in above. The correct one is List<Object> items = (List<Object>)root.get('score')
Arjun y 7Arjun y 7
I tried the above solution which present in link. It is not working.

My JSON Structure is:

"AAA": 0.1,
"BBB": 0.3, ..... } } For this i want to pass values in a list for score array only.
Temoc MunozTemoc Munoz
'score' is not a list but a set of Objects.

So, the only way you can get the values for score is through a series of chain events:
Map<String, Object> o = (Map<String, Object>)m.get('Accounts');
system.debug(o.get('score')); // This is an Object not a List<Object>

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: