I've such a json structure:
info:
{
First Name: "Robert",
Last Name: "Smith"
}
I'm tring to point to data with javascript using something like: "info.First Name" I know it's incorrect. How can I retrieve those information from the structure I have?
thank
JSON Simple Array ExamplesWhitespace (Space, Horizontal tab, Line feed or New line or Carriage return) does not matter in JSON. It can also be minified with no affect to the data.
We typically write JavaScript object properties using camelCase, without spaces, but you can use spaces in keys if you prefer. Just be sure to include quotation marks to specify the string you're using as the object key.
That's not valid JSON. JSON is a data transport format that requires field names to be string delimited with double quotes, e.g.
You can use \u0020 to escape a space in JSON.
To do this, you need to add an element to your JSON file, such as "_comment," which will contain your comment. The JSON API endpoint must ignore this particular JSON comment element. In this JSON comment example, we have included two comment elements in the JSON data, which you can see below.
That's not valid JSON. JSON is a data transport format that requires field names to be string delimited with double quotes, e.g.
{
"info" : {
"First Name": "Robert",
"Last Name": "Smith"
}
}
After parsing, you can then use obj.info["First Name"]
to access the First Name field.
What you have is a JS object literal (that's still invalid), but you can apply the same technique (stringify the property names) to reach the same end goal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With