How to convert a javascript object to json

I'm trying to convert a JavaScript object to a json.

Practically I have created a website where you can upload a json, edit it and download it with your changes.

For convenience when I edit it creates a javascript object that will be converted at the end of the changes with JSON.stringify .

The problem is that the final Json should have the same characteristics as the initial one with the elements associated to the different key.

For example the first one can be this:

"tickets": {
    "use": "Valida",
    "useagain": "Valida di nuovo",
    "usetitle": "Convalida biglietto",
    "usemessage": "Vuoi convalidare il biglietto ora?",
    "purchaseconfirmtitle": "Confermi l"acquisto?",
    "purchaseconfirmmessage": "Potrai convalidare il biglietto più tardi",
    "minutes": "Minuti",
}

The result must be like this:

"tickets": {
    "use": "Example",
    "useagain": "Example1",
    "usetitle": "Example2",
    "usemessage": "Example3,
    "purchaseconfirmtitle": "Example4",
    "purchaseconfirmmessage": "5",
    "minutes": "Minuti",
}

How do I make sure that all elements will be children of "ticket" (for example)?


According to W3Schools(consider following example),

var text = '{ "employees" : [' + '{ "firstName":"John" , "lastName":"Doe" },' + '{ "firstName":"Anna" , "lastName":"Smith" },' + '{ "firstName":"Peter" , "lastName":"Jones" } ]}';

Here is your object,

var obj = JSON.parse(text);

Here is the link.


您正在寻找JSON.stringify()。


I think you want to compare two javascript object.

Try this url

http://procbits.com/2012/01/19/comparing-two-javascript-objects

is that what you are looking for?

链接地址: http://www.djcxy.com/p/46288.html

上一篇: 使用JSON提交表单并使用PHP读取

下一篇: 如何将JavaScript对象转换为json