EDIT 2: Apparently Apex has no idea what escaping character is... after I removed manually all '\'
from that JSON, it worked.
I know this question was asked tens of times, but so far nothing works for me. I have a simple JSON from external application like this one:
"[{\"Birthdate\":\"2004-11-11\",\"City1\":\"city1\",\"City2\":\"city22\",\"Country1\":\"bg\",\"Country2\":\"BG2\",\"Description\":\"a random desc\",\"Email\":\"[email protected]\",\"Fax\":\"32424234242\",\"FirstName\":\"fir333stname\",\"HomePhone\":\"82937423\",\"LastName\":\"rggrdgr\",\"Phone\":\"4234234242\",\"PostalCode\":\"34233\",\"PostalCode2\":\"231\",\"State1\":\"gkrdg\",\"State2\":\"state2\",\"Title\":\"a very frustrated SF user\",\"MailingStreet\":\"fsdfsdfs\",\"OtherStreet\":\"fdjsnfkjsd\"},{\"Birthdate\":\"2004-11-11\",\"City1\":\"city1\",\"City2\":\"city22\",\"Country1\":\"bg\",\"Country2\":\"BG2\",\"Description\":\"a random desc\",\"Email\":\"[email protected]\",\"Fax\":\"32424234242\",\"FirstName\":\"firs444tname\",\"HomePhone\":\"82937423\",\"LastName\":\"rggrdgr\",\"Phone\":\"4234234242\",\"PostalCode\":\"34233\",\"PostalCode2\":\"231\",\"State1\":\"gkrdg\",\"State2\":\"state2\",\"Title\":\"a very frustrated SF user\",\"MailingStreet\":\"fsdfsdfs\",\"OtherStreet\":\"fdjsnfkjsd\"},{\"Birthdate\":\"2004-11-11\",\"City1\":\"city1\",\"City2\":\"city22\",\"Country1\":\"bg\",\"Country2\":\"BG2\",\"Description\":\"a random desc\",\"Email\":\"[email protected]\",\"Fax\":\"32424234242\",\"FirstName\":\"firstn555ame\",\"HomePhone\":\"82937423\",\"LastName\":\"rggrdgr\",\"Phone\":\"4234234242\",\"PostalCode\":\"34233\",\"PostalCode2\":\"231\",\"State1\":\"gkrdg\",\"State2\":\"state2\",\"Title\":\"a very frustrated SF user\",\"MailingStreet\":\"fsdfsdfs\",\"OtherStreet\":\"fdjsnfkjsd\"}]"`
And i am trying to deserialize it using: List<JSON2Apex> obj = System.JSON.deserialize(json, List<JSON2Apex>.class);
and my Json2Apex class look like this:
public class JSON2Apex {
public String Birthdate;
public String City1;
public String City2;
public String Country1;
public String Country2;
public String Description;
public String Email;
public String Fax;
public String FirstName;
public String HomePhone;
public String LastName;
public String Phone;
public String PostalCode;
public String PostalCode2;
public String State1;
public String State2;
public String Title;
public String MailingStreet;
public String OtherStreet;
}
Is is possible for the error to comes from this string coming from C# service and therefore being put inside "" quotes, instead of single one ''? And if so, how can I change that because splitting it to chars and remaking it with '' instead doesn't work.
String source = res.getBody();
String[] chars = source.split('');
String newJson = '';
for (Integer i = 1; i<chars.size();i++) {
newJson = newJson + chars[i];
}
The information there must be added to Contacts standard object, but I can't even extract it from that JSON.
P.S. - suggested answer didnt work.