You need to sign in to do that
Don't have an account?
VSK98
System.JSONException: Unexpected character ('C' (code 67)): was expecting comma to separate OBJECT entries
Hi All,
I am getting the error when I run the test class.
I have created the mock class, in that I am sending the body as below.
I am getting the error in Apex class
Wrapper class :
Regards,
VSK98
I am getting the error when I run the test class.
System.JSONException: Unexpected character ('C' (code 67)): was expecting comma to separate OBJECT entries
I have created the mock class, in that I am sending the body as below.
res.setBody('{"value": [{'+ '"groupid": 1,'+ '"group_name": "Test",'+ '"sub_customer": "[{\"CustomerId\":\"9488491\",\"CustomerName\":\"Test\",\"Street\":\"Test\",\"City\":\"PENRITH\",\"PostalCode\":\"275\",\"Country\":\"Test\",\"Assetcnt\":\"6\"}]"}]}');
I am getting the error in Apex class
SearchResult obj=(SearchResult)JSON.deserialize(resp.getBody(), SearchResult.class);
Wrapper class :
Public class value{ @AuraEnabled public Integer groupid {get; set;} @AuraEnabled public string group_name {get; set;} @AuraEnabled public String sub_customer {get; set;} } public class SearchResult { @AuraEnabled public List<value> value; public SearchResult(List<value> liList) { value = liList.clone(); } } Public class Value_out{ @AuraEnabled public string group_name; @AuraEnabled public string groupid; //srini-added for parent level sum of assets @AuraEnabled public String sumofAssets; @AuraEnabled public list<sub_customer> children; } public class sub_customer{ @AuraEnabled public string CustomerName; @AuraEnabled public string CustomerId; @AuraEnabled public string Street; @AuraEnabled public string City; @AuraEnabled public string PostalCode; @AuraEnabled public string Country; @AuraEnabled public string Assetcnt; }
Regards,
VSK98
String jsonStr ='{"value": [{'+
'"groupid": 1,'+
'"group_name": "Test",'+
'"sub_customer": "[{\\"CustomerId\\":\\"9488491\\",\\"CustomerName\\":\\"Test\\",\\"Street\\":\\"Test\\",\\"City\\":\\"PENRITH\\",\\"PostalCode\\":\\"275\\",\\"Country\\":\\"Test\\",\\"Assetcnt\\":\\"6\\"}]"}]}';
SearchResult v = (SearchResult)JSON.deserialize(jsonStr, SearchResult.class);
Output :
SearchResult:[value=(value:[group_name=Test, groupid=1, sub_customer=[{"CustomerId":"9488491","CustomerName":"Test","Street":"Test","City":"PENRITH","PostalCode":"275","Country":"Test","Assetcnt":"6"}]])]
All Answers
String jsonStr ='{"value": [{'+
'"groupid": 1,'+
'"group_name": "Test",'+
'"sub_customer": "[{\\"CustomerId\\":\\"9488491\\",\\"CustomerName\\":\\"Test\\",\\"Street\\":\\"Test\\",\\"City\\":\\"PENRITH\\",\\"PostalCode\\":\\"275\\",\\"Country\\":\\"Test\\",\\"Assetcnt\\":\\"6\\"}]"}]}';
SearchResult v = (SearchResult)JSON.deserialize(jsonStr, SearchResult.class);
Output :
SearchResult:[value=(value:[group_name=Test, groupid=1, sub_customer=[{"CustomerId":"9488491","CustomerName":"Test","Street":"Test","City":"PENRITH","PostalCode":"275","Country":"Test","Assetcnt":"6"}]])]
Regards,
VSK98