我有这个Json架构:
{
"name":"Myname",
"Job":"Myjob",
"item":{
"$ref": "#/definitions/address"
},
"definitions":
{
"address":
{
"street":"My street",
"postalCode":"11111"
}
}
}
我想知道JS是否有办法直接访问地址属性内容并通过“item”属性中存在的引用#/ definitions / address读取它。 所以我将在结果中得到Json对象:
"address":
{
"street":"My street",
"postalCode":"11111"
}
答案 0 :(得分:0)
如果你试图从你的地址索引引用的定义索引中访问地址对象,我想你可以用这种方式
<强> fiddle demo 强>
var object = {
"name":"Myname",
"Job":"Myjob",
"address":{
"$ref": "#/definitions/address"
},
"definitions":
{
"address":
{
"street":"My street",
"postalCode":"11111"
}
}
};
var add_ref = object.address.$ref.split('/');
console.log(object[add_ref[1]][add_ref[2]]);