简体   繁体   English

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

[英]convert the data received from url to json format

从 $.getJSON 我得到以下数据显示在图中

Is it possible to convert the the data shown in figure to following format:是否可以将图中所示的数据转换为以下格式:

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

What you're seeing is the browser attempting to show you the structure of the data.您看到的是浏览器试图向您展示数据的结构。 The actual structure is an array of objects as you would write it in code is:实际结构是一个对象数组,就像您在代码中编写的那样:

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

To convert the variable data to a JSON string, you would call:要将变量data转换为 JSON 字符串,您可以调用:

JSON.stringify(data);

This will return:这将返回:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM