You need to sign in to do that
Don't have an account?

how to parse below json response in apex
{ "destination_addresses" : [ "Bengaluru, Karnataka, India" ], "origin_addresses" : [ "Hyderabad, Telangana, India" ], "rows" : [ { "elements" : [ { "distance" : { "text" : "576 km", "value" : 575574 }, "duration" : { "text" : "8 hours 33 mins", "value" : 30763 }, "status" : "OK" } ] } ], "status" : "OK" }
Thanks
Thanks
Hi Hiteshwar,
Use something like : -
ThanksRajat Maheshwari
rajatzmaheshwari@gmail.com
The wrapper class for your response would be:
You could use tools such as JSON to Apex (https://www.adminbooster.com/tool/json2apex) to convert a JSON response into apex wrapper in future.
Hope this helps,
Sandeep
My json is
I want to print the value of definitions. Please help in this regard.
In order to parse a JSON and get the value you need, you need to get to the relevant Node, holding the value.
What you can do, is to Deserialize the JSON into Maps of (String, Object) or List of Maps of (String, Object) , in case the Node is an array, where the key is top Node and the value is the Peice of JSON of this Node.
e.g
"metadata": {
"provider": "Oxford University Press"
}
Map<String, Object> metadata_Map = (Map<String, Object>) JSON.deserializeUntyped('metadata');
This will give you a Map<String, Object> and you can fetch the value of 'provider' like this :
String providerVal = (String) metadata_Map.get('provider');
Elad
Hi K S R PAVAN KUMAR,
I think it's a late response check the below link it might help you
Parse JSON with Apex
https://salesforce.stackexchange.com/questions/262947/parse-json-with-apex
(https://github.com/open-force/jsonparse)
"token": "eyJraWQiOiIyNlN1NHFMNnVVZmlkIiwibW9iaWxlX3VzZXIiXSwic3"
How can I achieve this?