Solved

Serialize the array to JSON

Posted on 2012-03-29
4
413 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…

776 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