json fieldnames spaces [英] json fieldnames spaces
问题描述
我有这样一个json结构:
info:
{
名字:罗伯特,
姓氏:史密斯
}
我是使用javascript指向数据使用类似:info.First Name
我知道它是不正确的。
如何从我的结构中检索这些信息?
谢谢
这不是有效的JSON。 JSON是一种数据传输格式,要求字段名称用双引号进行字符串分隔,例如:
{
info:{
First Name:Robert,
姓氏:史密斯
}
}
解析后,然后,您可以使用 obj.info [First Name]
来访问First Name字段。
你所拥有的是一个JS对象文字(它仍然无效),但你可以应用相同的技术(字符串化属性名称)来达到相同的最终目标。 / p>
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
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.
这篇关于json fieldnames spaces的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!