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

How to get JSON field name ?
The JSON structure I am using is as follows :

I am trying to get the 'fr' inside the 'label' which is inside the 'version presentation'. I have tried so many times and here is my coding :
public class GetRestfulExampleSucces {
public string jsonStr {get;set;}
public Pagereference getJSONFromREST() {
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('http://dz.co.rplug.renault.com/pres/BAWg');
req.setHeader('Accept','application/JSON');
req.setMethod('GET');
HttpResponse res = h.send(req);
jsonStr= res.getBody();
List<String> calOut = new List<String>();
system.debug('jsonStr>>>>>>>>>>>>'+jsonStr);
JSONParser parser = JSON.createParser(jsonStr);
while (parser.nextToken() != null) {
if (parser.getCurrentToken() == JSONToken.FIELD_NAME){
String fieldName = parser.getText();
system.debug('fieldName >>>>>>>>>>>>'+fieldName );
if(fieldName == 'versionsPresentation'){
while(parser.nextToken() != null){
if(parser.getCurrentToken() == JSONToken.FIELD_NAME){
String Mname = parser.getText();
system.debug('Mname >>>>>>>'+Mname );
if(Mname == 'fr'){
parser.nextToken();
string version=parser.getText();
system.debug('version>>>>>>>'+version);
}
}
}
}
}
}
return null;
}
}
By using the above coding , I am getting again all the field values . Please provide me a solution for my query.
Thanks in advance !!!
I am trying to get the 'fr' inside the 'label' which is inside the 'version presentation'. I have tried so many times and here is my coding :
public class GetRestfulExampleSucces {
public string jsonStr {get;set;}
public Pagereference getJSONFromREST() {
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('http://dz.co.rplug.renault.com/pres/BAWg');
req.setHeader('Accept','application/JSON');
req.setMethod('GET');
HttpResponse res = h.send(req);
jsonStr= res.getBody();
List<String> calOut = new List<String>();
system.debug('jsonStr>>>>>>>>>>>>'+jsonStr);
JSONParser parser = JSON.createParser(jsonStr);
while (parser.nextToken() != null) {
if (parser.getCurrentToken() == JSONToken.FIELD_NAME){
String fieldName = parser.getText();
system.debug('fieldName >>>>>>>>>>>>'+fieldName );
if(fieldName == 'versionsPresentation'){
while(parser.nextToken() != null){
if(parser.getCurrentToken() == JSONToken.FIELD_NAME){
String Mname = parser.getText();
system.debug('Mname >>>>>>>'+Mname );
if(Mname == 'fr'){
parser.nextToken();
string version=parser.getText();
system.debug('version>>>>>>>'+version);
}
}
}
}
}
}
return null;
}
}
By using the above coding , I am getting again all the field values . Please provide me a solution for my query.
Thanks in advance !!!
for (String key : fieldMap.keySet()) {
Object value = fieldMap.get(key);
}
Using this one am geting the json string again.