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
rplrpl 

How do i go about parsing this json

{
    "name": "testparser",
    "org": "test",
    "email": "rpl@gmail.com",
    "courses": [
        {
            "cname": "this is course1",
             "startdate": "2014-04-12"
        },
        {
            "cname": "this is course2",
            "startdate": "2014-04-13"
        }
    ]
}
Ramu_SFDCRamu_SFDC
Please review the JSONParser class methods at the link http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_json_jsonparser.htm
Krrish KarthikKrrish Karthik
Hi you Change this type of String or u get particular part of this String...
rplrpl
I am looking to parse this JSON input in a webservice.
{
    "name": "testparser",
    "org": "test",
    "email": "rpl@gmail.com",
    "courses": [
        {
            "cname": "this is course1",
             "startdate": "2014-04-12"
        },
        {
            "cname": "this is course2",
            "startdate": "2014-04-13"
        }
    ]
}

I need to get the value of all the tokens in different fields.
cname and start date will be inserted as a custom object.
right now i am using this code but unfortunatly i have been able to store the name, org and email. I am facing an issue in parsing the array details

JSONParser jParser = JSON.createParser(input);
        while (jparser.nextToken() != NULL) {
            if (jparser.getCurrentToken() == JSONToken.FIELD_NAME){
                if (jparser.getText() == 'org'){
                    jparser.nextToken();
                    extInputs.Organization__c = jparser.getText();
                }
                else if (jparser.getText() == 'name'){
                    jparser.nextToken();
                    extInputs.Requestor_Name__c = jparser.getText();
                }
                else if(jparser.getText()=='email'){
                    jparser.nextToken();
                    extInputs.Email_Address__c = jparser.getText();
                }
                else if(jparser.getText()=='courses'){
                    if(jparser.getCurrentToken()==JSONToken.START_ARRAY){
                        while(jparser.getCurrentToken()!=JSONToken.END_ARRAY){
                            if (jparser.getCurrentToken() == JSONToken.FIELD_NAME)
                            {
                                if(jparser.getText()=='cname'){
                                    jparser.nextToken();
                                    courseList.add(jparser.getText());
                                }
                                else if(jparser.getText()=='startdate'){
                                   
                                }                               
                            //extInputs.Courses_Ordered__c=jparser.getText();
                            }
                            else{
                                jparser.nextToken();
                            }
                        }   
                        extInputs.Title_Position__c=courseList[0];
                        extInputs.Courses_Ordered__c=courseList[2];
                    }
                }
            }
        }