如何将javascript函数转换为json
How to turn javascript function to json
我正在使用动手表和jsfiddle http://jsfiddle.net/kc11/cb920ear/。其中有以下js函数:
function getCarData() {
return [
{car: "Mercedes A 160", year: 2006, available: true, comesInBlack: 'yes'},
{car: "Citroen C4 Coupe", year: 2008, available: false, comesInBlack: 'yes'},
{car: "Audi A4 Avant", year: 2011, available: true, comesInBlack: 'no'},
{car: "Opel Astra", year: 2004, available: false, comesInBlack: 'yes'},
{car: "BMW 320i Coupe", year: 2011, available: false, comesInBlack: 'no'}
];
}
这个数据结构是什么?我可以看到它不是 2d 数组或 json。有没有一种简单的方法可以将其更改为我需要从服务器接收以加载手动表的 json?
要将函数转换为 json do
JSON.stringify(getCarData, function(key, value) {
if (typeof value === 'function') {
return value.toString();
}
return value;
});
还""function getCarData() {'n return ['n {car: '"Mercedes A 160'", year: 2006, available: true, comesInBlack: 'yes'},'n {car: '"Citroen C4 Coupe'", year: 2008, available: false, comesInBlack: 'yes'},'n {car: '"Audi A4 Avant'", year: 2011, available: true, comesInBlack: 'no'},'n {car: '"Opel Astra'", year: 2004, available: false, comesInBlack: 'yes'},'n {car: '"BMW 320i Coupe'", year: 2011, available: false, comesInBlack: 'no'}'n ];'n }""
给我。请参阅 http://www.kristofdegrave.be/2012/07/json-serialize-and-deserialize.html
- 转换 JSON 日期,不考虑时区
- 转换 JSON 文件
- 使用正则表达式转换 JSON 密钥值
- 如何通过javascript转换JSON中的DC2type:数组和DC2type中的JSON
- 转换json中的整数值
- 转换JSON架构格式
- 转换JSON "/日期(1404860400000)"到javascript日期
- 在js中转换json数组
- 检索原始日期值转换JSON.stringify
- Java脚本转换json数据
- 用JS转换JSON字符串
- 转换JSON数组的对象,从两个属性值创建新的属性
- 在AngularJs中转换JSON对象
- 需要转换JSON格式
- 转换JSON中的字符串
- 如何转换json数组的JS
- jQuery UI自动完成与预转换json url
- 使用递归转换json数据
- 如何在jquery中转换json格式的数组
- 如何转换json没有& quot;