You need to sign in to do that
Don't have an account?

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"
}
]
}
"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"
}
]
}
{
"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];
}
}
}
}