Wednesday, August 31, 2011

JSON - Accessing object with hypen/dash

If you encounter json object that have - (hypen/dash) in the key, you will get a reference error if you access the object with dot manner. For example

{"cam-id":"1"}

Assuming the above object is call json_results, you will get an reference error if you

json_results.cam-id

You have to access the value by

json_results["cam-id"]

No comments:

Post a Comment

Sed - Example guide

sed is a very useful stream editor to perform search and replace. Below are some useful tip 1. Usage sed 's/apple/orange/' file...