I have a JSON string that I want to parse out. I have use the below code many times but for whatever reason this time it is not working. Can anyone poke any holes in this logic? Or point out why this may not be the best way to parse through a string?
String tokencred = [{"Id":"003m000000yKLySkkL","Token":"I2j5bUky04B4eLJGYELV"}]
JSONParser parser = JSON.createParser(tokencred);
//parse and map the returned string
while (parser.nextToken() != null) {
String parsedId;
String parsedToken;
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'Id')) {
parser.nextToken();
parsedId = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'Token')) {
parser.nextToken();
parsedToken = parser.getText();
}
tokenCredMap.put(parsedId,parsedToken);
}
system.debug('tokenCredMap:: ' + tokenCredMap);
14:31:15.0 (808193208)|USER_DEBUG|[153]|DEBUG|tokenCredMap:: {null=null, 003m000000yKLySkkL=null}
I do need the map as there is additional logic that will enable me to have multiple token/id combos.
UPDATE:
15:02:55.11 (726597242)|USER_DEBUG|[314]|DEBUG|this is the updated value [{"Id":"00Qm0000009qqdiEAA","Token":"J5h8yz004mFJi44ozuhw"}]
15:02:55.11 (727270334)|USER_DEBUG|[323]|DEBUG|fieldName: Id
15:02:55.11 (727412370)|USER_DEBUG|[323]|DEBUG|fieldName: Token
15:02:55.11 (727597218)|USER_DEBUG|[342]|DEBUG|tokenCredMap:: {null=null, 00Qm0000009qqdiEAA=null}
15:02:55.11 (732474914)|DML_BEGIN|[360]|Op:Update|Type:Lead|Rows:1