I am getting an error when I am trying to parse a JSON response from authorised.net.
System.JSONException: Unexpected character ('' (code 65279 / 0xfeff)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]
My JSON
{
"customerPaymentProfileIdList": [],
"customerShippingAddressIdList": [],
"validationDirectResponseList": ["1,1,1,(TESTMODE) This transaction has been approved.,000000,P,0,none,Test transaction for ValidateCustomerPaymentProfile.,1.00,CC,auth_only,,RAMESH,TEST,,TEST TEST,test,CA,2222,,,,[email protected],,,,,,,,,0.00,0.00,0.00,FALSE,none,BF4D71FADF17DA79C3B33ED0D2BA8438,,,,,,,,,,,,,XXXX0015,MasterCard,,,,,,,,,,,,,,,,,"],
"messages": {
"resultCode": "Error",
"message": [{
"code": "E00039",
"text": "A duplicate record with ID 1810594140 already exists."
}]
}
}
I have tried to parse this JSON by using create parser method.
JSONParser validationparser = JSON.createParser(res.getBody());
while (validationparser.nextToken() != null) {
if(validationparser.getText()=='validationDirectResponseList'){}
}
I also try to parse the same JSON by creating a JSON parser in apex class. But still getting the same error. Tried to change the Version from 39 to 30 but nothing worked.
public class JSON2Apex {
public class Messages {
public String resultCode;
public List<Message> message;
}
public class Message {
public String code;
public String text;
}
public List<CustomerPaymentProfileIdList> customerPaymentProfileIdList;
public List<CustomerPaymentProfileIdList> customerShippingAddressIdList;
public List<String> validationDirectResponseList;
public Messages messages;
public class CustomerPaymentProfileIdList {
}
public static JSON2Apex parse(String json) {
return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
}
}
Do anyone have any idea to resolve this issue. I totally get stuck with this. Thanks in advance.