I am grabbing values from a textarea with document.getElementById("textarea-id").value. I believe this grabs a object of type string.

我正在使用document.getElementById(“textarea-id”)。value从textarea中获取值。我相信这抓住了一个字符串类型的对象。

var b = document.getElementById("textarea-id").value

var b = document.getElementById(“textarea-id”)。value

I will JSON.stringify(b) because I have quotes in b so this will escape the quotes.

我将JSON.stringify(b)因为我在b中有引号所以这将逃避引号。

var c = JSON.stringy\ify(b)

var c = JSON.stringy \ ify(b)

I want to test if c is actually a JSON object. If it is, put each JSON object in an array. (there might be multiple JSON objects)

我想测试c是否实际上是一个JSON对象。如果是,请将每个JSON对象放在一个数组中。 (可能有多个JSON对象)

To me the easiest way to do so would be to separate the string by the ],[ values that separate the JSON objects. I'm not sure how to separate each object by ],[ while preserving the brackets.

对我来说,最简单的方法是通过],[分隔JSON对象的值来分隔字符串。我不确定如何通过]分隔每个对象,[同时保留括号。

example JSON object:

示例JSON对象:

[{
  "a":1,
  "b":2
}],
[{
  "c":3,
  "d":4
}]

1 个解决方案

#1


1

Consider ...

c = c.replace("],[", "]###[");
result = c.split("###");

... by using replace, we are changing the , between the ] [ to something unique that you can then split.

...通过使用替换,我们正在改变[之间]你可以拆分的独特之处。

更多相关文章

  1. 如何从Python脚本向jQuery发送JSON对象?
  2. jQuery 事件绑定方法(bind hover toggle live.... )、删除事件方法
  3. jQuery:在对象内使用.remove()而不是Regex
  4. ajax回调json数组对象,jquery中$.each()循环解析
  5. 触发具有相同类的另一个对象以使用计时器淡出
  6. 使用数字作为javascript对象元素的名称
  7. jQuery的deferred对象详解
  8. jQuery对象和DOM对象
  9. 如何修复JSON对象的假数组?

随机推荐

  1. MySQL+PHP配置 Windows系统IIS版(转)
  2. php分页代码的问题,显示了两个当前页码,求
  3. [轉]PHP官方网站,php官方论坛,中文函数手册
  4. 找不到go-pear。bat文件PHP 5.5 Windows
  5. 检索InnoDB组合密钥表的最后插入ID
  6. php 实现下载的方法
  7. 大文件从指定行开始读取
  8. 如何通过热门/上升的帖子订购
  9. mysql_query会自动执行,但不会在onClick时
  10. php写app接口并返回json数据