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

Apex code result as normal json
Hi!
I wrote Apex class:
@RestResource(urlMapping='/show/*')
global with sharing class User{
@HttpGet global static string doGet(){
Map < String, String > FieldMetaData = new Map< String, String >();
FieldMetaData.put('type', 'string');
FieldMetaData.put('label', 'label name');
FieldMetaData.put('name', 'first name');
FieldMetaData.put('length', '20');
String FieldMetaDataResult = JSON.serialize(FieldMetaData);
return FieldMetaDataResult ;
}
}
when I call it from php script the result is:
"{\"type\":\"string\",\"label\":\"label name\",\"length\":\"20\",\"name\":\"first name\"}"
How can I return result without slashes and double quotes? I need a normal json, namely:
{"type":"string","label":"label name","length":"20","name":"first name"}
Thank you!
I wrote Apex class:
@RestResource(urlMapping='/show/*')
global with sharing class User{
@HttpGet global static string doGet(){
Map < String, String > FieldMetaData = new Map< String, String >();
FieldMetaData.put('type', 'string');
FieldMetaData.put('label', 'label name');
FieldMetaData.put('name', 'first name');
FieldMetaData.put('length', '20');
String FieldMetaDataResult = JSON.serialize(FieldMetaData);
return FieldMetaDataResult ;
}
}
when I call it from php script the result is:
"{\"type\":\"string\",\"label\":\"label name\",\"length\":\"20\",\"name\":\"first name\"}"
How can I return result without slashes and double quotes? I need a normal json, namely:
{"type":"string","label":"label name","length":"20","name":"first name"}
Thank you!
Below is corrected code
@RestResource(urlMapping='/show/*')
global with sharing class User{
@HttpGet global static Map < String, String > doGet(){ // change return type from string to Map<string,string>
Map < String, String > FieldMetaData = new Map< String, String >();
FieldMetaData.put('type', 'string');
FieldMetaData.put('label', 'label name');
FieldMetaData.put('name', 'first name');
FieldMetaData.put('length', '20');
//String FieldMetaDataResult = JSON.serialize(FieldMetaData);// no need to serialize to string.
return FieldMetaData; // return Map it will return required clean json.
}
}
I did code this way and its working fine for us.