You need to sign in to do that
Don't have an account?
rahma salesforce
Cannot read HttpResponse.getBody() output
Hi,
I'm invoking a Rest Webservice from my developer org,
the issue is I can't read the HTTP Response as it is not proper json
this is the form of the response:
I'm using wrapper classes to extract the response as following:
System.JSONException: Malformed JSON: Expected '{' at the beginning of object
Is this because the HTTP response is not json ? it is specified in the content type though,
how can I convert the httpresponse body to json please ?
I'm invoking a Rest Webservice from my developer org,
the issue is I can't read the HTTP Response as it is not proper json
this is the form of the response:
[ { "attributes":{ "type":"Account", "url":"/services/data/v36.0/sobjects/Account/001580000054G7bAAE" }, "Id":"001580000054G7bAAE", "Name":"357", "Phone":"1233800" }, { "attributes":{ "type":"Account", "url":"/services/data/v36.0/sobjects/Account/001580000054G7cAAE" }, "Id":"001580000054G7cAAE", "Name":"358", "Phone":"1233801" }, { "attributes":{ "type":"Account", "url":"/services/data/v36.0/sobjects/Account/001580000054G7dAAE" }, "Id":"001580000054G7dAAE", "Name":"359", "Phone":"1233802" }, { "attributes":{ "type":"Account", "url":"/services/data/v36.0/sobjects/Account/001580000054G7eAAE" }, "Id":"001580000054G7eAAE", "Name":"360", "Phone":"1233803" }, { "attributes":{ "type":"Account", "url":"/services/data/v36.0/sobjects/Account/001580000054G7fAAE" }, "Id":"001580000054G7fAAE", "Name":"361", "Phone":"1233804" } ]
I'm using wrapper classes to extract the response as following:
public class Response{ public List<Account> accounts{get;set;} } public class Account{ public List<Attribute> attributes; public String Id; public String Name; public String Phone; } public class Attribute{ public String type; public String url; }but when trying to deserialize the reponse as the code below
Response response = (Response) JSON.deserialize(jsonResponse, Response.class);I have this error:
System.JSONException: Malformed JSON: Expected '{' at the beginning of object
Is this because the HTTP response is not json ? it is specified in the content type though,
how can I convert the httpresponse body to json please ?
All Answers
but still have this error now :
Line: 15, Column: 1
System.JSONException: Expected List<BatchGetDataFromDev1.Attribute> but found { at [line:1, column:3]
the attributes is not a list and should be an object