Solved

Serialize the array to JSON

Posted on 2012-03-29
4
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…

691 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