Read and Parse JSON String using ParseJSON Method with jQuery

Read and Parse JSON String using ParseJSON Method with jQuery
Introduction:
This article explains how to read and Parse JSON string in jQuery using ParseJSON method in JavaScript, asp.net and get string value from JSON string in jQuery.

To implement this functionality we need to write the code like as shown below

HTML Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Read and Parse Data using ParseJSON method</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
var name = '';
var jsonstr = '[{"UserName":"Ashwani","UserID":"1"},{"UserName":"VepshTech","UserID":"2"}]';
var obj = $.parseJSON(jsonstr);
$.each(obj, function() {
name += this['UserName'] + "<br/>";
});
$('#divjson').html(name); ;
})
</script>
</head>
<body>
<div id="divjson">
</div>
</body>
</html>

In above code we used parseJSON method to read formatted JSON string

Output:

Read and Parse JSON String using ParseJSON Method with jQuery


Ashwani
Ashwani

This is a short biography of the post author. Maecenas nec odio et ante tincidunt tempus donec vitae sapien ut libero venenatis faucibus nullam quis ante maecenas nec odio et ante tincidunt tempus donec.

No comments:

Post a Comment