作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
由于我的服务器端脚本输出方式,我收到多个 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/
我是一名优秀的程序员,十分优秀!