Json fieldnames namespaces

I have a json structure like this:

info: { First Name: "Robert", Last Name: "Smith" } 

I am trying to point to data using javascript using something like: "info.First Name" I know this is wrong. How can I get this information from the structure that I have?

thanks

+6
source share
1 answer

This is invalid JSON. JSON is a data transfer format that requires field names to be separated by double-quoted strings, for example.

 { "info" : { "First Name": "Robert", "Last Name": "Smith" } } 

After parsing, you can use obj.info["First Name"] to access the First Name field.

What you have is a JS object literal (which is still not valid), but you can apply the same technique (scribble property names) to achieve the same end goal.

+19
source

Source: https://habr.com/ru/post/886238/


All Articles