You need to sign in to do that
Don't have an account?
Parsing JSONArray in apex
i am trying to parse a response which is a json object in this json object there is a token with name items and whose value is a json array how to parse this json array
my json object is
{ "kind": "calendar#calendarList", "etag": "\"ZrhdJMCgpoUK_a5fT7XOC6xn46g/plXZGPvcPHrJh8umego5vRMYLrw\"", "items": [ { "kind": "calendar#calendarListEntry", "etag": "\"ZrhdJMCgpoUK_a5fT7XOC6xn46g/_sj3j6dReaKvgLTRpRDkSz1mIAU\"", "id": "#contacts@group.v.calendar.google.com", "summary": "Contacts' birthdays and events", "description": "Your contacts' birthdays and anniversaries", "timeZone": "Asia/Calcutta", "colorId": "12", "backgroundColor": "#fad165", "foregroundColor": "#000000", "selected": true, "accessRole": "reader" }, { "kind": "calendar#calendarListEntry", "etag": "\"ZrhdJMCgpoUK_a5fT7XOC6xn46g/wnz2e6fAz2dY8LnmrEb74dwcspc\"", "id": "en.indian#holiday@group.v.calendar.google.com", "summary": "Indian Holidays", "description": "Indian Holidays", "timeZone": "Asia/Calcutta", "colorId": "15", "backgroundColor": "#9fc6e7", "foregroundColor": "#000000", "selected": true, "accessRole": "reader" }, { "kind": "calendar#calendarListEntry", "etag": "\"ZrhdJMCgpoUK_a5fT7XOC6xn46g/hlANK5jBgx_YHUEAnXhn6WANZ4A\"", "id": "ritesh@iritesh.com", "summary": "ritesh@iritesh.com", "timeZone": "Asia/Calcutta", "colorId": "9", "backgroundColor": "#7bd148", "foregroundColor": "#000000", "accessRole": "owner", "defaultReminders": [ { "method": "popup", "minutes": 10 } ] } ] }
now for parsing i am using code
Map<String, Object> m =
(Map<String, Object>)
JSON.deserializeUntyped(re); //re is response body string
List<Object> a =
(List<Object>)m.get('items');
System.debug(String.valueOf(a.get(0)));
Map<String, Object> m1 =
(Map<String, Object>)
JSON.deserializeUntyped(String.valueOf(a.get(0)));
System.debug('Summary is'+m1.get('summary'));
System.debug(String.valueOf(a.get(0))); returning
{accessRole=reader, backgroundColor=#fad165, colorId=12, description=Your contacts' birthdays and anniversaries, etag="ZrhdJMCgpoUK_a5fT7XOC6xn46g/_sj3j6dReaKvgLTRpRDkSz1mIAU", foregroundColor=#000000, id=#contacts@group.v.calendar.google.com, kind=calendar#calendarListEntry, selected=true, summary=Contacts' birthdays and events, ...}
when i run this code i am getting error
FATAL_ERROR|System.JSONException: Unexpected character ('a' (code 97)): was expecting double-quote to start field name at [line:1, column:3]
because accessrole is ot surrounding with double quotes i am getting this error can any one please help how to get summary field from json array please provide a suitable method for parsing the response??
The object returned by parser is to type Map<String,Object>, hence it needs to be typecasted before using further in the code
This is a response of calendar list but I have one question that how do I pass event data of Google calendar feed in fullCalendar Api.