简体   繁体   English

如何在Javascript中从JSON格式获取数组?

[英]How to get array from JSON format in Javascript?

I have something like this... 我有这样的事......

["a","b","c"]

I got it from PHP array using json_decode(). 我是使用json_decode()从PHP数组中得到的。 I'm very weak in JavaScript, but I need to get array in Javascript, so I can use it with jQuery UI -> Autocomplete like this... 我在JavaScript方面很弱,但我需要在Javascript中获取数组,所以我可以在jQuery UI中使用它 - >像这样的自动完成...

source: [ 'a', 'b', 'c' ]

Is it possible to do with only Javascript or you need to have some Javascript library to use JSON? 是否可以只使用Javascript或者你需要一些Javascript库来使用JSON?

but I need to get array in Javascript, so I can use it with jQuery UI -> Autocomplete 但是我需要在Javascript中获取数组,所以我可以将它与jQuery UI一起使用 - >自动完成

Check out jQuery.parseJSON function. 查看jQuery.parseJSON函数。

Hey, You can do it only with javascript: 嘿,你只能用javascript做到这一点:

var arrayToUse = ["a","b","c"];

JSON stands for Javascript Object Notation and it is a standard notation for javascript objects. JSON代表Javascript Object Notation,它是javascript对象的标准表示法。 You do not need any special library to use it. 您不需要任何特殊库来使用它。 Example, 例,

If you want to create an object in javascript you would do something like: 如果你想在javascript中创建一个对象,你会做类似的事情:

var person = {
 name : 'somename',
source : arrayToUse
};

This is a javascript object in JSON notation 这是JSON表示法中的javascript对象

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

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