I have the following code:
JSON STRING (recordIDListJSON):
[\"a1mf0000000TU00AAG\", \"a1mf0000000TTzvAAG\", \"a1mf0000000KGFsAAO\"]"
This is a JSON.stringify of a JavaScript array. It contains record IDs which I want to assign to a List called recordIdList in my apex controller.
APEX CODE:
system.debug('Passed in value: '+ recordIdListJSON);
recordIdList = (List<String>)System.JSON.deserialize(recordIdListJSON,List<String>.class);
system.debug('Deserialized to: ' + recordIdList);
This is how I am trying to do it currently, but I'm getting the following error in the dev console logs:
FATAL_ERROR System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set
Can anybody tell me where I'm going wrong? Thanks!
Best Answer
I think you just need to sort out how you are defining your serialised string. Try this:
String recordIdListJSON = '[\"a1mf0000000TU00AAG\", \"a1mf0000000TTzvAAG\", \"a1mf0000000KGFsAAO\"]';
I've defined it with single quotes around the string - this works for the rest of your code and outputs the correct deserialised values.