gpt4 book ai didi

javascript - 关节 : i want to get the value of source": {"id": from json text

转载 作者:行者123 更新时间:2023-11-28 07:20:05 26 4
gpt4 key购买 nike

我想从这个 JSon 文本中使用 JSON 获取“source”中文本的值:{“id”:

{
"cells":
[
{
"type": "devs.Model", "size": { "width": 40, "height": 40 },
"inPorts": [""], "outPorts": [""], "position": { "x": 103, "y": 345 },
"angle": 0, "id": "4a8edbca-dd9d-4164-bf0a-fc4cbffdca86", "z": 1,
"attrs": {
".label": { "text": "aa", "ref-x": 0.4, "ref-y": 0.2 },
"rect": { "fill": "#2ECC71" },
".inPorts circle": { "fill": "#16A085", "magnet": "active", "type": "input" },
".outPorts circle": { "fill": "#E74C3C", "type": "output" },
".inPorts>.port0>.port-label": { "text": "" },
".inPorts>.port0>.port-body": { "port": { "id": "in8", "type": "in" } },
".inPorts>.port0": { "ref": ".body", "ref-y": 0.5 },
".outPorts>.port0>.port-label": { "text": "" },
".outPorts>.port0>.port-body": {
"port": { "id": "out9", "type": "out" }
},
".outPorts>.port0": { "ref": ".body", "ref-y": 0.5, "ref-dx": 0 }
}
},
{
"type": "link", "source": {}, "target": {}, "id": "35173392-8b69-44fc-b6f4-f7c8a62319bb", "z": 2, "attrs": {}
},
{
"type": "devs.Model", "size": { "width": 40, "height": 40 },
"inPorts": [""], "outPorts": [""], "position": { "x": 603, "y": 488 },
"angle": 0, "id": "39e8bc7f-0553-4c5a-b198-b948b0905ae7", "z": 3,
"attrs": {
".label": { "text": "aaa", "ref-x": 0.4, "ref-y": 0.2 },
"rect": { "fill": "#2ECC71" },
".inPorts circle": { "fill": "#16A085", "magnet": "active", "type": "input" },
".outPorts circle": { "fill": "#E74C3C", "type": "output" },
".inPorts>.port0>.port-label": { "text": "" },
".inPorts>.port0>.port-body": { "port": { "id": "in15", "type": "in" } },
".inPorts>.port0": { "ref": ".body", "ref-y": 0.5 },
".outPorts>.port0>.port-label": { "text": "" },
".outPorts>.port0>.port-body": { "port": { "id": "out16", "type": "out" } },
".outPorts>.port0": { "ref": ".body", "ref-y": 0.5, "ref-dx": 0 }
}
},
{
"type": "link", "source": { "id": "4a8edbca-dd9d-4164-bf0a-fc4cbffdca86", "selector": "g:nth-child(1) g:nth-child(4) g:nth-child(1) circle:nth-child(1) ", "port": "out9" },
"target": { "id": "39e8bc7f-0553-4c5a-b198-b948b0905ae7", "selector": "g:nth-child(1) g:nth-child(3) g:nth-child(1) circle:nth-child(1) ", "port": "in15" },
"id": "19bfe3a0-bb48-4665-8f2b-807c3bc33451", "embeds": "", "z": 4,
"attrs": { ".marker-target": { "d": "M 10 0 L 0 5 L 10 10 z" } }
}]
}

我愿意

var t = JSON.stringify(graph )+"";
var obj = jQuery.parseJSON(t);
alert(obj.cells[3].source['.id']);

但是不起作用

最佳答案

您不需要字符串化然后重新解析它。只需访问该字段:

alert(graph.cells[3].source.id);

关于javascript - 关节 : i want to get the value of source": {"id": from json text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30398462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com