Friends:
I am trying to pass a variable into query.outfields.
When it is hard coded it works. Coming in as an object.
query.outFields = ["OBJECTID", "NAME"];
Passing in the JSON variable does not work.
query.outFields = JSON.parse(FieldNames); // "['OBJECTID', 'Name']" (value in query parameter through FFox)
I am getting a JSON error in the browser that says it cannot recognize the square bracket [ .
Any suggestions on how to pass in JSON variables into query.output would be great.
Keith
I think the problem is the single quotes around OBJECTID and Name. JSON only allows double-quotes as string delimiters. You'll need to replace the single quote characters with double quotes.
I have tried everything I know without any luck.
"extentlatlon":"[-93.45,44.93]", JSON.parse on that extent works.
"FeatureOutputFields":"[OBJECTID,NAME]" JSON.parse on those fields do not.
"FeatureOutputFields":"[“OBJECTID,NAME”]” No go
"FeatureOutputFields":"[“OBJECTID”,”NAME”]” No go
Thanks for the effort.
The following method worked for me:
var temp = '{"FeatureOutputFields":["SQMI", "STATE_NAME", "STATE_FIPS", "SUB_REGION", "STATE_ABBR"]}';
var temp1 = JSON.parse(temp);
query.outFields = temp1.FeatureOutputFields;
You can test the application here: Edit fiddle - JSFiddle
Thanks Nic.
I will remember your effort!
Jeff told me to try escape characters and I eventually got it going.
You'll need to escape the double quotes since the string is delimited by double quotes.
{
"FeatureOutputFields": "[\"OBJECTID,NAME\"]"
}
This was the final result for me:
"FeatureOutputFields":"[\"OBJECTID\",\"NAME\"]"
Keith