Solved

Serialize the array to JSON

Posted on 2012-03-29
4
408 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
Comment Utility
0
 
LVL 15

Expert Comment

by:navneethegde
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now