In the previous section of example we have studied how to create message in JSON in JavaScript and now we will come to know that how we can parse the message in JSON in JavaScript.
We can parse the message with JSON in JavaScript by using the method "String.parseJSON(filter)". It parses the JSON message to an string or object. The parameter "filter" is optional in this method which is used to filter message or transform their results. This method internally uses the JavaScript's method eval() to parse messages.
Here is the full example code for ParseMessageJSON.htm as follows:
ParseMessageJSON.htm
<html>
|
To run this example we need to have json2.js file included with our ParseMessageJSON.htm file. File "json2.js" is as same as in our previous example of "creating message in JavaScript with JSON" .
Run ParseMessageJSON.htm file on your browser.
It will generate output on your browser as follows:



If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Parsing a message in JavaScript with JSON
Post your Comment