You need to sign in to do that
Don't have an account?
Siddhartha Tomar 12
how to add response in lightning component
I have one requirement where i am getting the below response from third party and now i wanted to show the response field on lightning component . Can any one help me how to desrialized it into list so that i can add it on lightning component
{
"rates": [
{
"advertised": 0.0299,
"combined": 0,
"from_amt": 0,
"to_amt": 0.1599,
"code": "ABC1899",
},
{
"advertised": 0.0299,
"combined": 0,
"from_amt": 0,
"to_amt": 0.1599,
"code": "ABC1899",
},
{
"advertised": 0.0299,
"combined": 0,
"from_amt": 0,
"to_amt": 0.1599,
"code": "ABC1899",
},
{
"advertised": 0.0299,
"combined": 0,
"from_amt": 0,
"to_amt": 0.1599,
"code": "ABC1899",
}
],
}
{
"rates": [
{
"advertised": 0.0299,
"combined": 0,
"from_amt": 0,
"to_amt": 0.1599,
"code": "ABC1899",
},
{
"advertised": 0.0299,
"combined": 0,
"from_amt": 0,
"to_amt": 0.1599,
"code": "ABC1899",
},
{
"advertised": 0.0299,
"combined": 0,
"from_amt": 0,
"to_amt": 0.1599,
"code": "ABC1899",
},
{
"advertised": 0.0299,
"combined": 0,
"from_amt": 0,
"to_amt": 0.1599,
"code": "ABC1899",
}
],
}
Greetings to you!
You can use JSON.parse in the client-side controller or you can use JSON.deserialize in server-side controller. Please refer to the below links which might help you further with the above requirement.
https://salesforce.stackexchange.com/questions/169507/getting-the-json-values-in-a-component
https://salesforce.stackexchange.com/questions/175170/parse-a-json-and-use-it-in-lightning
https://salesforce.stackexchange.com/questions/160846/is-there-any-function-to-deserialize-an-json-to-an-array-in-lightning-component
https://salesforce.stackexchange.com/questions/214224/how-can-i-parse-my-json-blob-in-my-lightning-component
https://developer.salesforce.com/forums/?id=9060G0000005XPPQA2
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
1 . You can parse it in apex class using json parsing and return the wrapper class to ui and its easy to do it
2 . Parsing by using the Javascript Parsing .. i will not recommend this because you need to do a lot of loops ( using ES6 maps ,forEach ect )
3 . Set the json object in attribute and using the aura:iteration to loop though the values
https://salesforce.stackexchange.com/questions/202701/json-parsing-and-aura-iteration-in-salesforce-lightning/202704
https://developer.salesforce.com/index.php?title=Getting_Started_with_Apex_JSON
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_jsonparser.htm
http://www.salesforcenextgen.com/how-to-do-json-parsing-of-a-wrapper-class-in-salesforce/
http://bobbuzzard.blogspot.com/2015/07/lightning-components-and-custom-apex.html
http://www.infallibletechie.com/2017/07/how-to-display-wrapper-class-list-in.html