如何将数组的JavaScript数组转换成JSON字符串 [英] How to convert a Javascript Array of Arrays into a JSON String

查看:84
本文介绍了如何将数组的JavaScript数组转换成JSON字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaScript数组转换为JSON字符串的一个复杂的例子。

I have a complicated example of converting a Javascript Array to a JSON String.

比方说,我有两个类型的对象。第一类型被称为属性,它具有字段:标识,URI,标签和值[]其中值是第二类型的对象的阵列

Let's say I have two type of objects. The first type is called a Property, it has the fields: id, uri, label and values[] where values is an array of the second type of object.

第二类型的对象,称作价值具有字段:标识,URI,标签

The second type of object, called a Value has the fields: id, uri, label.

如果我有一个简单的数组,我相信我会做:VAR arrayAsJSON = myarray.stringify();将这项工作在这种情况下。我已经尝试过了,它回来为未定义,但也许我做一些别的错误的。

If I had a simple Array I believe I would do: var arrayAsJSON = myarray.stringify(); Would this work in this case. I have tried it and it comes back as undefined, but perhaps I am doing some else wrong.

推荐答案

在常见的,你可以使用JSON.stringify(阵列),但不是所有的浏览器都有这个方法来实现。然而,如果你使用一些JS框架字符串化可能是实现有旧的浏览器。

In common you can use JSON.stringify(array), but not all browsers have this method implemented. However if you use some JS framework stringify is probably implemented there for old browsers.

这篇关于如何将数组的JavaScript数组转换成JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆