Showing posts with label Json. Show all posts
Showing posts with label Json. Show all posts

Monday, 4 February 2013

Turn javascript object into a string

use json2.js from http://www.JSON.org/json2.js

e.g.
<script src="json2.js"></script>
...
JSON.stringify( {
    FirstName: $('#FirstName').val(),
    LastName: $('#LastName').val()
});

To turn a JSON string into javascript ojbect, use parseJSON.

var json = '{"fname" : "john", "lname" : "smith", "age" : 35}';
var jsObject = $.parseJSON(json);


WCF returning Json data

in the .net world, we need to get the data by getting the property d like this:

var cust = data.d[0];

var cust = data.d.firstname;

this won't work: var cust = data[0];