double quotes in output json string

5 views
Skip to first unread message

Beau

unread,
Nov 3, 2009, 2:13:51 PM11/3/09
to inputex
Hi, I'm having trouble with double quotes in the json string generated
by getValue(). My output json looks like this:

{"Keywords":{"Keywords":"("civil engineer" or "construction engineer")
and highway and
bridge","SearchPattern":"BOO","JobTitle":"","Company":"","School":"","JobCategories":
[""]},"Location":
{"City":"","State":"CA","ZipCode":"","Country":"US","SearchRadiusInMiles":"","RelocationFilter":""},"Preferences":
{"EmploymentType":"ALL","MinimumExperience":"RENS","MinimumTravelRequirement":"RTNS","MinimumDegree":"CE31","CompensationType":"SALR","MinimumSalary":"","MaximumSalary":"","CurrentlyEmployed":"","ManagementExperience
":"","MinimumEmployeesManaged":"","MaximumCommute":""},"Options":
{"FreshnessInDays":"60","ExcludeResumesWithNoSalary":"","WorkStatus":"CTNS","OrderBy":"-
MODIFIEDINT"}}

and I url encode this and pass it to a php page for some ajax
processing. Trouble is with the Keywords field (and potentially any
other text input field) where a user can use double quotes. In my
keywords field, the user is allowed to use quotes to specify phrases
they would like to search on.

So, this string works fine in the browser with JS, but when passed to
PHP, the json_decode() function craps out.

I read somewhere that proper json uses double quotes to delimit the
values, and my search script cannot use single quotes for phrases.

anyone have any ideas on how to get around this?

Thanks

Dawa Lama

unread,
Nov 3, 2009, 4:58:47 PM11/3/09
to inp...@googlegroups.com
Maybe you can post-process the data and escape the quotes, using js before submitting the form .

Dawa
--
Dawa L. Sherpa

Kay Roesler

unread,
Nov 9, 2009, 2:43:35 PM11/9/09
to inputex
That's what I did:

1. build your array in php
2. mark your javascript part within your php in a way like

$jsPrefix = "%%%";
$jsPostfix = "%%%";
$array['onclick'] = $jsPrefix . "function(){ ... }" . $jsPostfix;

3. $sting = json_encode($array)
4. str_replace($jsPrefix, $string) and the same for Postfix
5. use json in javascript.

The only thing I experienced was that I could not use regular yui json
parse because the syntax is not save. You will have to use eval.

Kay
Reply all
Reply to author
Forward
0 new messages