Fields with a plus

10 views
Skip to first unread message

Rob Waterson

unread,
Nov 20, 2011, 6:06:05 PM11/20/11
to Open State Project
I feel like this might be a dumb question but I cannot figure it out.
I am getting some of the non-standard fields back with a plus but when
I try to de-reference them I do not get anything out. For example, the
GA legislator data has a field called +city but if I try $leg[+city],
I get nothing. Am I being obtuse here? Do I need to strip out pluses
or something at some point?

Thanks in advance,

Rob

Rob Waterson

unread,
Nov 20, 2011, 6:42:15 PM11/20/11
to Open State Project
Sorry, in case it was not clear, this is in PHP.

James Turk

unread,
Nov 22, 2011, 11:09:39 AM11/22/11
to fifty-sta...@googlegroups.com
Hi Rob,

It's been a long time since I've used PHP, are you using whatever
JSON-parsing it has natively or are you using some library? That is
the most likely culprit.

-James

> --
> You received this message because you are subscribed to the Google Groups "Open State Project" group.
> To post to this group, send email to fifty-sta...@googlegroups.com.
> To unsubscribe from this group, send email to fifty-state-pro...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/fifty-state-project?hl=en.
>
>

Shane Daniel

unread,
Dec 8, 2011, 3:03:09 PM12/8/11
to Open State Project
Hi Rob,

From php's json_decode manual page: http://php.net/manual/en/function.json-decode.php#example-3320

"Accessing elements within an object that contain characters not
permitted under PHP's naming convention (e.g. the hyphen) can be
accomplished by encapsulating the element name within braces and the
apostrophe."

<?php

$json = '{"foo-bar": 12345}';

$obj = json_decode($json);
print $obj->{'foo-bar'}; // 12345

?>

Similarly, $leg->{"+city"} should de-reference correctly.

hth,

Shane

Reply all
Reply to author
Forward
0 new messages