gpt4 book ai didi

javascript - 如何在 JavaScript 中解析这个 JSON 对象?

转载 作者:行者123 更新时间:2023-12-03 09:49:35 27 4
gpt4 key购买 nike

在这里寻找一些关于如何提取 Alok、Test 和 Test2 的指导

对象 {value: "{"actors":["Alok","Test","Test2"]}"}

我几乎花了一整天的时间来找出解析这个 JSON 数组的方法,但我最接近的方法是将所有字符打印在一行中。

我的 JavaScript 实现是:

        AJS.$.ajax({
dataType: 'json',
type: 'GET',
url: AJS.params.baseURL+"/rest/leangearsrestresource/1.0/message/list/{actor}",
async: false,
multiple: true
}).done(function(result) {
AJS.log(result);
//var obj = JSON.parse(result);
//AJS.log(obj.actors[1]);

//AJS.log("Actor is " + result.length);
var output = '';
for(var key in result) {
AJS.log("Key: " + key + " value: " + result[key]);
var myThing = result[key];
var output = myThing.property
AJS.log(output)
// AJS.log(output.text)
for( thingKey in myThing ) {

AJS.log(myThing[thingKey])
}

}

还附上控制台截图enter image description here

最佳答案

结果对象未完全解析,它有一个包含字符串的属性值,因此您必须像这样解析 value 属性的值: JSON.parse(result.value) 并且您将获得一个具有一个属性的对象“actor”,其值为包含字符串“Alok”、“Test”、“Test2”的数组。

关于javascript - 如何在 JavaScript 中解析这个 JSON 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30915505/

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