function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AlSawtoothAlSawtooth 

Why is JSONParser.getText() null?

I have the following debugs in my code:
System.debug(parser.nextToken());
System.debug(parser.getCurrentToken());
System.debug(parser.getCurrentName());
System.debug(parser.getText());

I get (in order):
DEBUG| FIELD_NAME
DEBUG| FIELD_NAME
DEBUG| originalId 
DEBUG| null
Why is getText() null? My code uses a while looop to go through a ton of these, and they all have the same pattern - and getText() is null for all of them.

Thank you!
 
AlSawtoothAlSawtooth
In case it's helpful, here is a larger snippet of my code:
JSONParser parser = JSON.createParser(res.getbody());
        while(parser.nextToken() != null){
        
        if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getCurrentName() == 'originalId')){
               String return2 = parser.getText();
               }
        
        System.debug(parser.nextToken());
        System.debug(parser.getCurrentToken());
        System.debug(parser.getCurrentName());
        System.debug(parser.getText());
        System.debug(return2);
        }

Per the documentation, getText() "Returns the textual representation of the current token or null if there's no current token.No current token exists, and therefore this method returns null, if nextToken has not been called yet for the first time or if the parser has reached the end of the input stream." So in my example, getCurrentToken() returns a value, and nextToken() is being called in the while loop. What am I missing?

(Documentation link: http://www.salesforce.com/us/developer/docs/dbcom_apex230/Content/apex_methods_system_jsonparser.htm)