如何从以下JSON对象获取javascript数组 - [英] How to get javascript array from the following JSON object-

查看:65
本文介绍了如何从以下JSON对象获取javascript数组 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var object ='{name:PHP Tutorial,Description:Web技术专家};

var object='{"name":"PHP Tutorial","Description":"Expert in web technology"}';

推荐答案

正如Mehdi所说在他对这个问题的评论中,这不是一个数组,而是一个JavaScript 对象,它带有键值对,键是属性名,值是相应的属性值。但任何JavaScript对象都可以被视为关联数组。这样的数组与JavaScript数组不同,JavaScript数组是一个专门的对象(基本上具有属性 length ;面向使用用作属性名的整数,但是任何种类的属性可以混合在同一个对象中。)



也就是说,你必须至少学习JavaScript的主要原则请参阅:

JavaScript - 维基百科,免费的百科全书 [ ^ ],

关联数组 - 维基百科,免费的百科全书 [ ^ ]。



关于数组对象作为专门的JavaScript对象,请阅读

数组 - JavaScript | MDN [ ^ ]。



最后,这是将JSON字符串解析为对象的方式:

JSON.parse() - JavaScript | MDN [ ^ ],

另见: JSON - JavaScript | MDN [ ^ ]。



-SA
As Mehdi said in his comment to the question, this is not an array, but is a JavaScript object, which comes with key-value pairs, key being a property name, and value — the respective property value. But any JavaScript object can be considered as an associative array. Such array is not the same as JavaScript array, which is a specialized object (essentially with the property length; oriented to the use of integers used as property names, but any kinds of properties can be mixed in the same object).

That said, you have to learn at least main principles of JavaScript Please see:
JavaScript — Wikipedia, the free encyclopedia[^],
Associative array — Wikipedia, the free encyclopedia[^].

About arrays objects as specialized JavaScript objects, please read
Array — JavaScript | MDN[^].

Finally, this is how you parse JSON string into an object:
JSON.parse() — JavaScript | MDN[^],
see also: JSON — JavaScript | MDN[^].

—SA


这篇关于如何从以下JSON对象获取javascript数组 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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