I am trying to parse json response as follows:
["India",["India","India\u2013United States Civil Nuclear Agreement","Indian rupee"],["India, Test"],["https://en.wikipedia.org/wiki/India","https://en.wikipedia.org/wiki/India%E2%80%93United_States_Civil_Nuclear_Agreement"]]
Wrapper class:
public class fromJSON{
public String Text; //India
public List<jsonTitles> jsonTitles;
public List<jsonDetails> jsonDetails;
public List<jsonURL> jsonURL;
public class jsonTitles{}
public class jsonDetails{}
public class jsonURL{}
public static fromJSON parse(String responseBody ){
System.debug('@@@@@@@' +JSON.deserialize(responseBody , fromJSON.class));
return (fromJSON) System.JSON.deserialize(responseBody , fromJSON.class);
}
}
I am unbale to do as I land up with this error
Malformed JSON: Expected '{' at the beginning of object
I have concatenated json string to solve this issue I am getting following error after that:
System.JSONException: Unexpected character ('[line:1, column:3]
What I can understand from JSON is, it is in array with out key value pairs.
I have used deserialize methods of salesforce but unable to do this.Can anyone help me with snippet or the approach.??
But I am able to do with javascript: If JSON validator says it is valid response.Then with apex I should be able to do it??
How it is possible using JavaScript:
parseResult : function(res,helper){
var retJSON = JSON.parse(res);
var jsonTitles = retJSON[1] ;
var jsonDetails = retJSON[2];
var jsonURL = retJSON[3];
var domSearch = document.getElementById('resultPlaceHolder');
while (domSearch.firstChild) {
domSearch.removeChild(domSearch.firstChild);
}
for(var i=0 ; i<jsonTitles.length ; i++)
{
helper.createChildNodes(domSearch, jsonTitles[i],jsonDetails[i],jsonURL[i]);
}
}