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

How to convert JSON to apex format. I'm getting internal server error when i tried to deserialize. Please help
@AuraEnabled
public static String insertinfo(String caseId, String accountId, List<String> results)
{
system.debug('ffmap'+results);
list<objectWrap> myWrap = (list<objectWrap>)results; //Getting error here . Also ffmap is not coming in the valid format
}
ffmap log :- ({key=123, value={key1=KEITH W PETERSON, key2=123, key3=null, key4=Bronze, key5=31-Jan-2019}}, {key=456, value={key1=JOYCE P WEST, key2=456, key3=xdkzwhzorm@uaowz.qca, key4=Bronze, key5=31-Jul-2018}})
From helper i am getting proper json format whereas in the apex ctrlr am getting the result in valid format
My helper class :-
CreateHelper: function(component, event) {
//call apex class method
var action = component.getinsertinfo
var myMap = component.get("v.selectednos");
console.log('Mymapvalue' + myMap);
action.setParams({
"caseId": component.get("v.CaseId"),
"accountId" : component.get("v.AccountId"),
"results" : myMap
});
log:-
Mymapvalue' :- [{"key":"123","value":{"key1":"KEITH W PETERSON","key2":"123","key3":null,"key4":"Bronze","key5":"31-Jan-2019"}},{"key":"456","value":{"key1":"JOYCE P WEST","key2":"456","key3":"xdkzwhzorm@uaowz.qca","key4":"Bronze","key5":"31-Jul-2018"}}]
public static String insertinfo(String caseId, String accountId, List<String> results)
{
system.debug('ffmap'+results);
list<objectWrap> myWrap = (list<objectWrap>)results; //Getting error here . Also ffmap is not coming in the valid format
}
ffmap log :- ({key=123, value={key1=KEITH W PETERSON, key2=123, key3=null, key4=Bronze, key5=31-Jan-2019}}, {key=456, value={key1=JOYCE P WEST, key2=456, key3=xdkzwhzorm@uaowz.qca, key4=Bronze, key5=31-Jul-2018}})
From helper i am getting proper json format whereas in the apex ctrlr am getting the result in valid format
My helper class :-
CreateHelper: function(component, event) {
//call apex class method
var action = component.getinsertinfo
var myMap = component.get("v.selectednos");
console.log('Mymapvalue' + myMap);
action.setParams({
"caseId": component.get("v.CaseId"),
"accountId" : component.get("v.AccountId"),
"results" : myMap
});
log:-
Mymapvalue' :- [{"key":"123","value":{"key1":"KEITH W PETERSON","key2":"123","key3":null,"key4":"Bronze","key5":"31-Jan-2019"}},{"key":"456","value":{"key1":"JOYCE P WEST","key2":"456","key3":"xdkzwhzorm@uaowz.qca","key4":"Bronze","key5":"31-Jul-2018"}}]
2) What type of data does your JSON hold? It looks like a custom object of the following format: Is that correct? It's a map of maps of strings? If so, you would process your JSON as such: What this is doing is:
1) Declaring that myResults is an object that will contain a map, and that map will contain maps, and those maps will be of strings. You shouldn't need a wrapper class for this purpose.
2) It deserializes your string into that format.
I believe that should do it.
Would it be possible to directly iterate the results like below if i get valid json format from ightning java script ctrlr
public static String addParentCase(String caseId, String accountId, string results)
for(String myff : results) {
}
Your data arrives as a String, which needs to be processed as JSON and converted into an appropriate object. Since your data is a Map of Maps, it's not a list either.
What you *could* do is after you've converted your string into a Map of Maps: This will loop through every object within myResults and make it available to you as myMap.
Based on your sample data, it would look like this: Putting it all together:
I believe it's struggling with the opening '[' in your json string. Could you try remove the brackets from the beginning and end of your json string before sending it to the apex? They can also be stripped within the apex, but you might as well give it clean data right up front.
So your Apex error is telling you "You already told me this is an object. You can't change your mind and tell me it's a map of strings and objects."