How To Create Json Data In Js
I would like to create a json object such as this that I can send to the server: { 'email': 'some@gmail.com', 'profile': { 'token': 'test' } } I can create the JS
Solution 1:
Most modern browsers have JSON.stringify(yourData) and JSON.parse(jsonData);
Solution 2:
Just create your object as a plain JavaScript object:
varobject = {
email: "some@gmail.com",
profile: {
token: "test"
}
}
Then convert it to JSON:
var json = JSON.stringify(object);
Solution 3:
var dataModel = {
email: "somemail@gmail.com",
profile: {
token: "sometoken"
}
};
var dataModelJSON = JSON.stringify(dataModel);
Supported by main browsers: http://caniuse.com/#search=JSON.stringify
Solution 4:
try:
var dataModel = { email: "somemail@gmail.com"};
dataModel.profile = {token : "test"}
Post a Comment for "How To Create Json Data In Js"