Solved

Serialize the array to JSON

Posted on 2012-03-29
4
415 Views
Last Modified: 2012-03-31
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.
0
Comment
Question by:zhshqzyc
  • 2
4 Comments
 
LVL 21

Expert Comment

by:masterpass
ID: 37784431
0
 
LVL 15

Expert Comment

by:navneethegde
ID: 37785847
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!
0
 

Author Comment

by:zhshqzyc
ID: 37786840
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.
0
 
LVL 21

Accepted Solution

by:
masterpass earned 500 total points
ID: 37789489
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question