JSON Messages with JavaScript

Posted on Updated on

Image result for json iconJSON Messages with JavaScript

Creating and Parsing JSON Messages with JavaScript continues…

vary arrayAsJSONText = ‘[“Europe”, “Asia”, “Australia”, “Antarctica”,

 “North America”, “South America”, “Africa”]’;

var continents = eval( arrayAsJSONText );

alert(continents[0] + ” is one of the ” + continents.length + “


Obviously, by and by the assessed JSON content will originate from some outside source as opposed to being hard-coded as in the above case. The eval work indiscriminately assesses whatever expression it is passed. A dishonest source could subsequently incorporate possibly perilous JavaScript alongside or blended into the exacting documentation that makes up the JSON information. In situations where the source can’t be believed, it is profoundly prescribed that you parse the JSON content utilizing the parseJSON() work (found in json.js):

// Requires json.js

var continents = arrayAsJSONText.parseJSON();

The parseJSON() work additionally utilizes eval, however just if the string contained in arrayAsJSONText complies with the JSON content standard. It does this utilizing a cunning consistent expression test.

Working with JSON in the .NET Framework

JSON content can without much of a stretch be made and parsed from JavaScript code, which is a piece of its appeal. In any case, when JSON is utilized as a part of an ASP.NET web application, just the program appreciates JavaScript bolster since the server-side code is undoubtedly composed in Visual Basic or C#.

Most Ajax libraries intended for ASP.NET give support to automatically making and parsing JSON content. Thusly, to work with JSON in a .NET application, consider utilizing one of these libraries. There are a lot of open-source and outsider choices, and Microsoft additionally has their own Ajax library named ASP.NET AJAX.

In this article we will take a gander at cases that utilization Jayrock, an open-source usage of JSON for the Microsoft .NET Framework made by coauthor Atif Aziz. We utilized Jayrock rather than ASP.NET AJAX for three reasons: Jayrock is open-source, making it conceivable to expand or tweak as required. Jayrock can be utilized as a part of ASP.NET 1.x, 2.0, and Mono applications, though ASP.NET AJAX is for ASP.NET rendition 2.0 as it were. Jayrock’s extension is constrained to JSON and JSON-RPC, and the previous is the principle center of this article. While ASP.NET AJAX incorporates some support for making and parsing JSON content, its basic role is to offer a rich stage for building end-to-end Ajax-style web applications in ASP.NET. The additional fancy odds and ends can occupy when your fundamental concentration is JSON. Working with JSON in .NET utilizing Jayrock is like working with XML through the XmlWriter, XmlReader, and XmlSerializer classes in the .NET Framework. The classes JsonWriter, JsonReader, JsonTextWriter, and JsonTextReader found in Jayrock emulate the semantics of the .NET Framework classes XmlWriter, XmlReader, XmlTextWriter, and XmlTextReader. These classes are helpful for interfacing with JSON at a low-and stream-arranged level. Utilizing these classes, JSON content can be made or parsed piecemeal through a progression of technique calls. For instance, utilizing the JsonWriter class technique WriteNumber(number) works out the suitable string representation of number as per the JSON standard. The JsonConvert class offers Export and Import strategies for changing over between .NET sorts and JSON. These strategies give a comparable usefulness as found in the XmlSerializer class techniques Serialize and Deserialize, separately.

Making JSON Text

The accompanying code outlines utilizing the JsonTextWriter class to make the JSON content for a string cluster of mainlands. This JSON content is sent to a TextWriter occurrence go into the constructor, which happens to be the yield stream from the reassure in this case (in ASP.NET you can utilize Response.Output):


For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.
Helpline: 9814666333, 8699444666
Email: info@technocampus.co.in

Please fill the form and we shall contact you soon.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s