• Anil Pandey
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Software Engineer
  • HCL

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
JSONParser parser = JSON.createParser(res.getbody());
        while(parser.nextToken() != null){
        
        if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getCurrentName() == 'originalTeamId')){
               String returnteam = parser.getText();
               }
        
        System.debug(parser.nextToken());
        System.debug(parser.getCurrentToken());
        System.debug(parser.getCurrentName());
        System.debug(parser.getText());
        System.debug(returnteam);
        }        
             
    if(returnteam != null){
        teams[0].OldTeamId__c = returnteam;
    }

Per the documentation (http://www.salesforce.com/us/developer/docs/dbcom_apex230/Content/apex_methods_system_jsonparser.htm), the getText() method "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."

In my debug above, getCurrentToken() returns a value, and nextToken() is called in the while loop. Why is getText() null in the debug?

Please suggest !!!
JSONParser parser = JSON.createParser(res.getbody());
        while(parser.nextToken() != null){
        
        if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getCurrentName() == 'originalTeamId')){
               String returnteam = parser.getText();
               }
        
        System.debug(parser.nextToken());
        System.debug(parser.getCurrentToken());
        System.debug(parser.getCurrentName());
        System.debug(parser.getText());
        System.debug(returnteam);
        }        
             
    if(returnteam != null){
        teams[0].OldTeamId__c = returnteam;
    }

Per the documentation (http://www.salesforce.com/us/developer/docs/dbcom_apex230/Content/apex_methods_system_jsonparser.htm), the getText() method "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."

In my debug above, getCurrentToken() returns a value, and nextToken() is called in the while loop. Why is getText() null in the debug?

Please suggest !!!