• #29850
    Forcetalks

    Which parsing method is better – Deserialisation or JSON Parser? And Why?

    Which parsing method is better – Deserialisation or JSON Parser? And Why?

    Tagged: , , , , , , , , ,

    #29852
    Forcetalks

    JSON is the most preferred way of transferring data over web. We use this most in salesforce when integrating with an external system. In most of the integrations, you typically use HTTP Callouts to the end points defined by various services, and the most common response format returned by these is JSON. Parsing this JSON would be very time consuming . One way of doing this would be manually parsing the complete JSON using the JSONParser method but Deserialization parsing method is better because

    <Class/Object> n = (<Class/Object>)JSON.deserialize(‘JSON’, <Class/Object>.class);

    This one statement would completely deserialize the JSON and store the values in the respective member variables of the class.

    #29862
    Forcetalks

    Hello Shradha,

    I would say JSON Deserialization is better because it’s an automatic parser while in JSON Parser method, you need to parse JSON manually.

    Thanks.

    #35211
    Salesforce | shariq shariq #1
    Forcetalks

    Hi,

    I would Use JSON Deserialization.

    jsonStr = ‘{//some JSON data}’
    JSONParser parser = JSON.createParser(jsonStr);
    String text = ”;
    while (parser.nextToken() != null) {
    if(parser.getCurrentToken() == JSONToken.START_OBJECT){
    parser.nextToken();
    text = parser.getText() + ‘, ‘ + text;
    }
    //System.debug(parser.getText() + parser.nextToken() + ‘ – ‘ + parser.getText());
    if (parser.getCurrentToken() == JSONToken.START_ARRAY) {
    //parser.nextToken();
    text = parser.getText() + ‘, ‘ + text;
    }
    }

    Hope this helps.

Viewing 4 posts - 1 through 4 (of 4 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?