You need to sign in to do that
Don't have an account?
Visualforce Error: System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set
Hi All,
I am getting 'System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set ' exception while parsing json, Please help
Thanks.
I am getting 'System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set ' exception while parsing json, Please help
Thanks.
public class JSONWrapper{ public cls_result[] result{get;set;} class cls_result { public String parent{get;set;} // public String made_sla{get;set;} //true public String caused_by{get;set;} // public String watch_list{get;set;} // public String upon_reject{get;set;} //cancel public String sys_updated_on{get;set;} //2017-06-20 07:52:14 public String child_incidents{get;set;} //0 public String hold_reason{get;set;} // public String approval_history{get;set;} // public String number1{get;set;} //5002800000m9AD4AAM public String resolved_by{get;set;} // public String sys_updated_by{get;set;} //admin public cls_opened_by opened_by{get;set;} public String user_input{get;set;} // public String sys_created_on{get;set;} //2017-06-20 07:52:14 public cls_sys_domain sys_domain{get;set;} public String state{get;set;} //1 public String sys_created_by{get;set;} //admin public String knowledge{get;set;} //false public String order{get;set;} // public String calendar_stc{get;set;} // public String closed_at{get;set;} // public String cmdb_ci{get;set;} // public String delivery_plan{get;set;} // public String impact{get;set;} //3 public String active{get;set;} //true public String work_notes_list{get;set;} // public String business_service{get;set;} // public String priority{get;set;} //5 public String sys_domain_path{get;set;} /// public String rfc{get;set;} // public String time_worked{get;set;} // public String expected_start{get;set;} // public String opened_at{get;set;} //2017-06-20 07:52:14 public String business_duration{get;set;} // public String group_list{get;set;} // public String work_end{get;set;} // public cls_caller_id caller_id{get;set;} public String resolved_at{get;set;} // public String approval_set{get;set;} // public String subcategory{get;set;} // public String work_notes{get;set;} // public String short_description{get;set;} //This is test incident created from salesforce CRM public String close_code{get;set;} // public String correlation_display{get;set;} // public String delivery_task{get;set;} // public String work_start{get;set;} // public String assignment_group{get;set;} // public String additional_assignee_list{get;set;} // public String business_stc{get;set;} // public String description{get;set;} // public String calendar_duration{get;set;} // public String close_notes{get;set;} // public String notify{get;set;} //1 public String sys_class_name{get;set;} //incident public String closed_by{get;set;} // public String follow_up{get;set;} // public String parent_incident{get;set;} // public String sys_id{get;set;} //b2472d10db23320085fe72ffbf961960 public String contact_type{get;set;} // public String incident_state{get;set;} //1 public String urgency{get;set;} //3 public String problem_id{get;set;} // public cls_company company{get;set;} public String reassignment_count{get;set;} //0 public String activity_due{get;set;} // public String assigned_to{get;set;} // public String severity{get;set;} //3 public String comments{get;set;} // public String approval{get;set;} //not requested public String sla_due{get;set;} // public String comments_and_work_notes{get;set;} // public String due_date{get;set;} // public String sys_mod_count{get;set;} //0 public String reopen_count{get;set;} //0 public String sys_tags{get;set;} // public String escalation{get;set;} //0 public String upon_approval{get;set;} //proceed public String correlation_id{get;set;} // public String location{get;set;} // public String category{get;set;} //inquiry } class cls_opened_by { public String link{get;set;} public String value{get;set;} } class cls_sys_domain { public String link{get;set;} public String value{get;set;} } class cls_caller_id { public String link{get;set;} public String value{get;set;} } class cls_company { public String link{get;set;} public String value{get;set;} } public List<JSONWrapper> parse(String json){ return (List<JSONWrapper>) System.JSON.deserialize(json, List<JSONWrapper>.class); } }
public class ServiceNowCntrl { public string bodyText{get;set;} public ServiceNowCntrl (){ doInit(); } public void doInit(){ try{ string user='xxx'; string password='xxxxxxxx'; HttpRequest request = new HttpRequest(); request.setEndpoint('https://dev18687.service-now.com/api/now/table/incident?sysparm_limit=10'); Blob auth = Blob.valueOf(user+':'+password); System.debug('Auth: '+ auth); String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(auth); request.setMethod('GET'); request.setHeader('Authorization', authorizationHeader); request.setHeader('Content-Type', 'application/json;charset=UTF-8'); Http http = new Http(); HttpResponse res = new HttpResponse(); res = http.send(request); system.debug(res.getBody()); bodyText=res.getBody(); JSONWrapper jw=new JSONWrapper(); list<JSONWrapper> jwList=new List<JSONWrapper>(); jwList=jw.parse(bodyText); }catch(System.CalloutException e){ System.debug('Erro: '+ e.getMessage()); } } }
and this for your parser: