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

JSON Parsing of Phone number

hello All,


Can anyone tell how to parse phone number from the following response:


DEBUG|HTTPResponse Body :{
"to_number":"(989) 914-3756",


My Code:
while (parser.nextToken() != null) {

if( parser.getCurrentName() == 'to_number'){
newSMS.To__c = parser.getText();
System.debug('SMS TO: '+parser.getText());
if( parser.getCurrentName() == 'direction'){
newSMS.Direction__c = parser.getText();
System.debug('SMS Dir: '+parser.getText());
if( parser.getCurrentName() == 'message_type'){
newSMS.Type__c = parser.getText();
System.debug('SMS Dir: '+parser.getText());
if( parser.getCurrentName() == 'content'){
newSMS.Msg__c = parser.getText();
System.debug('SMS Msg: '+parser.getText());
if( parser.getCurrentName() == 'Status'){
newSMS.Status__c = parser.getText();
System.debug('SMS Statue: '+parser.getText());


I am able to parse other field, only not able to parse to_number. Can someone help?


Why don't you just deserialize into a map, like so:


map<string,string> info = (map<string,string>)json.deserialize(res.getbody(),map<string,string>.class);

You can get the phone via:


String phoneNumber = info.get('to_number');

Much faster than trying to parse everything yourself.


However, as to why 'to_number' isn't working, I don't have an answer for that. Your code looks like it should work.


Thanks for the Ry.

Anyway i was able to get the parsing going right.!!