• Mohammad Zakir Hossain
  • NEWBIE
  • 15 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi,
I am struggling with parsing JSON for object of array values with other fields.
The problem is unable to define variable set in wrapper class for "linked_objects": { "jobcodes": [ 27251018 ] } .

According to below code it gives error:
FATAL_ERROR System.JSONException: Expected List<CalloutTSheets.linked_objects> but found { at...


Use Case :
parse json with keeping two value pair by wrapper class and json filed linked_objects is object type which contains Array set of values. So  to parse the json string , along with other values need to extract jobcodes array in defined wrapper class WOTSheetsLocWrap .

Sample JSON
"results": {
        "locations": {
            "5214198": {
                "id": 5214198,
                "addr1": "33W401 Roosevelt"
             ..
                "linked_objects": {
                    "jobcodes": [
                        27251018
                    ]
                }
            }

Sample Apex Code:
public class WOTSheetsLocWrap{
        public String id;
        public String addr1;        
        List<linked_objects> linked_objects;
    }   
    public class linked_objects{
        String [] jobcodes = new List<String>();     
    }   
......
		Map<String, String> WOTSLocMap = new Map<String, String>();

        system.debug('resLoc');

        system.debug(resLoc.getBody());

        JSONParser parserLoc = JSON.createParser(resLoc.getBody());
        parserLoc.nextToken();
        parserLoc.nextToken();
        parserLoc.nextToken();
		parserLoc.nextToken();
		parserLoc.nextToken();
        while(parserLoc.nextToken()!=NULL){
            parserLoc.nextToken();
            if(parserLoc.getCurrentToken()==JSONToken.START_OBJECT){
				CalloutTSheets.WOTSheetsLocWrap obj = (CalloutTSheets.WOTSheetsLocWrap)parserLoc.readValueAs(CalloutTSheets.WOTSheetsLocWrap.class);
				if(!String.isBlank(obj.id)) WOTSLocMap.put(obj.addr1,obj.id);
                system.debug('obj');

            }
        }
    system.debug(WOTSLocMap);


Thanks in Advance...
I am facing CORS error when accessing image by javascript from visualforce page.
I have already tried adding to CORS whitelisting and remote settings too ..

If I use external image link it works but what ever image use from salesforce content version it shows such error even I tried with sfdc cv public image ContentDownloadUrl.

my use case is exporting image as pdf by html2pdf library .

 
Access to image at 'https://...content.force.com/sfc/dist/version/download/?oid=...&asPdf=false' from origin 'https://....visual.force.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

 
Hi,
I am struggling with parsing JSON for object of array values with other fields.
The problem is unable to define variable set in wrapper class for "linked_objects": { "jobcodes": [ 27251018 ] } .

According to below code it gives error:
FATAL_ERROR System.JSONException: Expected List<CalloutTSheets.linked_objects> but found { at...


Use Case :
parse json with keeping two value pair by wrapper class and json filed linked_objects is object type which contains Array set of values. So  to parse the json string , along with other values need to extract jobcodes array in defined wrapper class WOTSheetsLocWrap .

Sample JSON
"results": {
        "locations": {
            "5214198": {
                "id": 5214198,
                "addr1": "33W401 Roosevelt"
             ..
                "linked_objects": {
                    "jobcodes": [
                        27251018
                    ]
                }
            }

Sample Apex Code:
public class WOTSheetsLocWrap{
        public String id;
        public String addr1;        
        List<linked_objects> linked_objects;
    }   
    public class linked_objects{
        String [] jobcodes = new List<String>();     
    }   
......
		Map<String, String> WOTSLocMap = new Map<String, String>();

        system.debug('resLoc');

        system.debug(resLoc.getBody());

        JSONParser parserLoc = JSON.createParser(resLoc.getBody());
        parserLoc.nextToken();
        parserLoc.nextToken();
        parserLoc.nextToken();
		parserLoc.nextToken();
		parserLoc.nextToken();
        while(parserLoc.nextToken()!=NULL){
            parserLoc.nextToken();
            if(parserLoc.getCurrentToken()==JSONToken.START_OBJECT){
				CalloutTSheets.WOTSheetsLocWrap obj = (CalloutTSheets.WOTSheetsLocWrap)parserLoc.readValueAs(CalloutTSheets.WOTSheetsLocWrap.class);
				if(!String.isBlank(obj.id)) WOTSLocMap.put(obj.addr1,obj.id);
                system.debug('obj');

            }
        }
    system.debug(WOTSLocMap);


Thanks in Advance...
I am facing CORS error when accessing image by javascript from visualforce page.
I have already tried adding to CORS whitelisting and remote settings too ..

If I use external image link it works but what ever image use from salesforce content version it shows such error even I tried with sfdc cv public image ContentDownloadUrl.

my use case is exporting image as pdf by html2pdf library .

 
Access to image at 'https://...content.force.com/sfc/dist/version/download/?oid=...&asPdf=false' from origin 'https://....visual.force.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.