You need to sign in to do that
Don't have an account?
PC
Get particular json element value using apex
Below is the json data i am recieving.I want to get the value of datetime,accesskey and accesssecret in apex
{"hotelogix":{"version":"1.0","datetime":"2019-11-13T05:40:14","response":{"status":{"code":0,"message":"success"},"accesskey":"0vi1yR7ssx4IMrw","accesssecret":"rbgTdw6kfpE8ZQV"},"request":{"method":"wsauth","key":"5151BE0BE4A9B667C07"}}}
Greetings to you!
This tool will parse the JSON for you and create a class: http://json2apex.herokuapp.com/
which results in this:
And then you can parse the JSON and you can reference it in code.
Try this in Execute Anonymous Window:
Alternatively, you can use System.JSON.deserializeUntyped(json); as suggested by Chandrika.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Here you have to deserialize the JSON string inorder to access it in apex.For this use deserialize methods of JSON class.
Please refer this links which might help you further
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm
https://developer.salesforce.com/forums/?id=906F0000000kE2DIAU
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
Greetings to you!
This tool will parse the JSON for you and create a class: http://json2apex.herokuapp.com/
which results in this:
And then you can parse the JSON and you can reference it in code.
Try this in Execute Anonymous Window:
Alternatively, you can use System.JSON.deserializeUntyped(json); as suggested by Chandrika.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
I have gone through your question. There is a class named 'JSONParser' in salesforce that can be used to deserialize JSON data.
Please check the link below for details -
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_jsonparser.htm
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com