Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将从url接收的数据转换为json格式_Javascript - Fatal编程技术网

Javascript 将从url接收的数据转换为json格式

Javascript 将从url接收的数据转换为json格式,javascript,Javascript,是否可以将图中所示的数据转换为以下格式: Object {glossary: Array[4]} glossary : Array[4] __proto__: Object 您看到的是浏览器试图向您显示数据的结构。实际结构是一个对象数组,正如您在代码中编写的那样: [{firstname: "Fozzy", lastname: "The Foz", title: "Garbage Disposal..."}, {...}, {...}] 要将变量数据转换为JSON字符串,可以调用: JSON

是否可以将图中所示的数据转换为以下格式:

Object {glossary: Array[4]}
glossary : Array[4]
__proto__: Object

您看到的是浏览器试图向您显示数据的结构。实际结构是一个对象数组,正如您在代码中编写的那样:

[{firstname: "Fozzy", lastname: "The Foz", title: "Garbage Disposal..."}, {...}, {...}]
要将变量数据转换为JSON字符串,可以调用:

JSON.stringify(data);
这将返回:

"[{"firstname": "Fozzy", "lastname": "The Foz", "title" : "Garbage Disposal..."}, {...}, {...}]"

你能解释一下你想做什么吗?@S你是想转换成JSON还是做其他事情?代码块和您拥有的图像是浏览器,向您显示对象是什么以及它包含什么。我使用以下方法解决:$.ajax{dataType:json,url:'persons.json',success:function data{data={'roles':data};var html=Mustache.to_html$'tpl'.html,数据;$'car'.htmlhtml;}