Link to home
Start Free TrialLog in
Avatar of zhshqzyc
zhshqzyc

asked on

Serialize the array to JSON

Hello, I am new to JSON. Now in my asp.net code behind there is an array. I want to use it in javascript(jquery). I heard a new term "JSON" and serialize etc., but just no idea about it.

string[] source = new string[5];
         source[0] = "c++";
         source[1] = "java";
         source[2] = "php";
         source[3] = "coldfusion";
         source[4] = "javascript"; 

Open in new window

How to start it? I need details such as download something and so on.
Avatar of masterpass
masterpass
Flag of India image

Avatar of Navneet Hegde
Hi!

Download this script and include into your project
https://github.com/douglascrockford/JSON-js/blob/master/json2.js

and then simply call
var myJsonString = JSON.stringify(source);

Thanks!
Avatar of zhshqzyc
zhshqzyc

ASKER

Let me rewrite the question, actually I want to pass the array from asp.net array to javascript code.
My original idea was to use jquery to complete autocomplete. The sample code:

A simple jQuery UI Autocomplete.
http://docs.jquery.com/UI/Autocomplete
 
$("input#autocomplete").autocomplete({
    source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
});
 

Open in new window

Here source is hard copied, but in the real world case, it is from database. I extracted it from the database and formed it as a list or an array. Now the question is how to pass it to javascript.
I need code assistance or at least a small sample.
ASKER CERTIFIED SOLUTION
Avatar of masterpass
masterpass
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial