最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - How to get array from JSON format in Javascript? - Stack Overflow

programmeradmin2浏览0评论

I have something like this...

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

I got it from PHP array using json_decode(). I'm very weak in JavaScript, but I need to get array in Javascript, so I can use it with jQuery UI -> Autoplete like this...

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

Is it possible to do with only Javascript or you need to have some Javascript library to use JSON?

I have something like this...

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

I got it from PHP array using json_decode(). I'm very weak in JavaScript, but I need to get array in Javascript, so I can use it with jQuery UI -> Autoplete like this...

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

Is it possible to do with only Javascript or you need to have some Javascript library to use JSON?

Share Improve this question asked Jan 2, 2011 at 7:02 daGrevisdaGrevis 21.3k39 gold badges103 silver badges139 bronze badges 1
  • Consider: <script>var myObj = <?= encode_your_php_object_to_json(...) ?>;</script> and what it implies. See json for more details. – user166390 Commented Jan 2, 2011 at 7:15
Add a ment  | 

2 Answers 2

Reset to default 5

but I need to get array in Javascript, so I can use it with jQuery UI -> Autoplete

Check out jQuery.parseJSON function.

Hey, You can do it only with javascript:

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

JSON stands for Javascript Object Notation and it is a standard notation for javascript objects. 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:

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

This is a javascript object in JSON notation

发布评论

评论列表(0)

  1. 暂无评论