gpt4 book ai didi

javascript - 解析 JSON 时出现 jQuery 错误

转载 作者:行者123 更新时间:2023-12-02 18:40:08 25 4
gpt4 key购买 nike

我正在尝试解析这个 JSON 字符串:

{"946cb446-cee6-488d-9f2c-0088e173975d":"/slide7.jpg",
"d120b1c9-58d2-4eb6-94ec-052cf6323dea":"/slide24.jpg",
"2da5187c-1bc2-4bc6-a4f0-0d2cf1be3689":"/slide21.jpg",
"299002c3-22f8-4428-8f38-1310b58ac113":"/slide26.jpg",
"ec46f5ad-7a42-4ebc-935a-16a4f4adcfe3":"/slide27.jpg",
"4bccd0b8-b684-4861-93b3-17759893a1cd":"/slide44.jpg",
"3d430596-04ff-4103-9a70-300ed992bd5c":"/slide14.jpg",
"ba9f4550-8844-4733-b3cb-31a6a57efc7d":"/slide45.jpg",
"994e49f7-6346-46a3-a6ee-322789fc0142":"/slide6.jpg",
"be1f5e2e-4ac6-4f6b-aae2-3af212de1d09":"/slide30.jpg",
"094c304d-1afb-409e-aa3e-3bfb050e5eaf":"/slide40.jpg",
"2cf38f65-9587-4d21-96c0-3e093f8017eb":"/slide3.jpg",
"813a470f-807a-41e3-8ad9-3e0fb8f043ee":"/slide16.jpg",
"1e7c1d9b-0adc-42f1-a1cc-3f9279d9faa1":"/slide31.jpg",
"36f62a81-d360-4892-82be-5121b0bcf137":"/slide39.jpg",
"4218f4c7-3997-4266-bcc2-58659cf43fab":"/slide1.jpg",
"248c8fbc-7be5-4531-89bb-5aaf25017667":"/slide2.jpg",
"645e7869-68d5-4e61-ad6b-5c2aafb455a5":"/slide8.jpg",
"c541462d-51eb-473a-aa2f-5c30ed2c3e89":"/slide13.jpg",
"02a2b45a-56a6-4e39-80f9-6c9c300bf19d":"/slide18.jpg",
"1e9ce967-c923-425b-b048-6f4a5738b05f":"/slide32.jpg",
"4e86ed21-472e-4916-9a54-73158a1891e3":"/slide23.jpg",
"90a646a8-5d9c-42e2-916c-7439630f4cda":"/slide22.jpg",
"e9fbd50c-a470-4420-b0c8-747c810587d7":"/slide5.jpg",
"d5181fd2-4e5e-4866-a76a-74c9f97d6090":"/slide46.jpg",
"2355c1b9-a484-40cb-9040-7c9db3737019":"/slide9.jpg",
"22b2d09e-0abb-46d2-a503-9c54e9a953fa":"/slide37.jpg",
"eae0ca42-f873-4508-a228-a94b5e9b7454":"/slide42.jpg",
"9fc385ae-ecc1-41ce-bfd1-b1e9f5e8cd34":"/slide11.jpg",
"040e95af-3e28-421d-b975-b5ab3c267c6e":"/slide20.jpg",
"cb3d0743-ec2f-4a63-9a26-c978c19851c4":"/slide15.jpg",
"b019f69d-de71-4f7f-9d44-c9d6185e4966":"/slide38.jpg",
"085fdd67-2e32-4f09-a93b-cf1ba81fd4a3":"/slide33.jpg",
"099bb24f-489f-40ab-aa4e-d3c5c499cbee":"/slide28.jpg",
"ff4f04ef-a114-4cce-9f91-d5b129f86d80":"/slide41.jpg",
"b9e8c44f-b838-4bb7-8e06-d9b38e24a6e2":"/slide35.jpg",
"e9785a7e-0673-40dc-a8c8-e25e01ca39e3":"/slide4.jpg",
"5519594f-5f99-4681-b2f9-e2c49b56d838":"/slide25.jpg",
"082dcb2f-8396-42a8-a83e-e478c90e1059":"/slide10.jpg",
"93647403-b429-4e68-9d8a-ea7cf7e0ff35":"/slide36.jpg",
"7d79f12a-9649-46f8-867c-ebffa2fc2adb":"/slide17.jpg",
"1be6980a-8a75-449f-af59-efec739a0177":"/slide34.jpg",
"457538fa-87b9-4fb2-bf80-fa63278bd0eb":"/slide19.jpg",
"20499f07-da0f-4e6e-9c44-faf74f737644":"/slide43.jpg",
"01815f25-7dab-4bf7-aede-fd074128332c":"/slide12.jpg",
"7c913e57-65ae-458a-a8c0-fd2c9c17b813":"/slide29.jpg"}

这样:

success: function (msg) {
var arr = msg.d;

// Replace the div's content with the page
$.each(arr, function (index, element) {
var text = "<li>" + element + "</li>";
var newli = $(text);

$("#listPages").append(text);
});

我收到以下错误:

未捕获类型错误:无法使用“in”运算符在 {"946cb446-cee6-488d-9f2c-0088e173975d":"/slide7.jpg"} 中搜索“53”

一些帮助?

最佳答案

我猜你的响应数据是简单的字符串 - 所以你必须解析它以在数据对象中转换,或在回调函数中解析

success: function (msg) {
JSON.parse(msg.d, function (key, value) {
var text = "<li>" + value+ "</li>";
var newli = $(text);
$("#listPages").append(text);
}
});

这是附加信息 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

关于javascript - 解析 JSON 时出现 jQuery 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16922508/

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