gpt4 book ai didi

jquery - 如何在JQuery中使用$.each循环遍历json代码

转载 作者:行者123 更新时间:2023-12-01 07:36:53 30 4
gpt4 key购买 nike

由于我的服务器端脚本输出方式,我收到多个 JSON 对象。 {jsonhere}{jsonhere1}{jsonhere2}{jsonhere3} 等等.. 它们没有被任何东西分开。如果我进行基于 }{ 的拆分,我将丢失这些括号。那么是否有一个外循环可以覆盖常规的 $.each 循环来完成这项工作?

谢谢,

最佳答案

粗略算法:

Define a stack
Define an array
LOOP on each character in the string
IF the top item of the stack is a single or double quote THEN
LOOP through each character until you find a matching single or double quote, then pop it from the stack.
ELSE
IF "{", push onto the stack
IF "}" THEN
pop a "{" from the stack if it is on top
IF the stack is empty THEN //we just finished a full json object
Throw this json object into an array for later consumption
END IF
END IF
IF single-quote, push onto the stack
IF double-quote, push onto the stack
END IF
END LOOP

关于jquery - 如何在JQuery中使用$.each循环遍历json代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/337766/

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