The first code is an example of Javascript code, which is similar, however not JSON.(第一个代码是Javascript代码的示例,它类似,但不是JSON。)
JSON would not have 1) comments and 2) the var
keyword(JSON不会有1)注释和2) var
关键字)
You don't have any comments in your JSON, but you should remove the var
and start like this:(你的JSON中没有任何注释,但你应该删除var
并像这样开始:)
orders: {
The [{}]
notation means "object in an array" and is not what you need everywhere.([{}]
符号表示“数组中的对象”,并不是您需要的所有内容。) It is not an error, but it's too complicated for some purposes.(这不是错误,但对于某些目的而言太复杂了。) AssociatedDrug should work well as an object:(AssociatedDrug应该作为一个对象很好地工作:)
"associatedDrug": {
"name":"asprin",
"dose":"",
"strength":"500 mg"
}
Also, the empty object labs should be filled with something.(此外,空对象实验室应该填充一些东西。)
Other than that, your code is okay.(除此之外,你的代码还可以。) You can either paste it into javascript, or use the JSON.parse()
method, or any other parsing method (please don't use eval )(您可以将其粘贴到javascript中,也可以使用JSON.parse()
方法或任何其他解析方法(请不要使用eval ))
Update 2 answered:(更新2回答:)
obj.problems[0].Diabetes[0].medications[0].medicationsClasses[0].className[0].associatedDrug[0].name
returns 'aspirin'.(返回'阿司匹林'。) It is however better suited for foreaches everywhere(然而,它更适合各地的森林) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…