How do I convert this javascript into JSON -
How can I structured my data, such as saying, is a question that is associated with 5 options, and The vote of each option is associated with it? If you think of it as a tree, the question is, the root, which has 5 leaves, is the option, and every option has only one leaf, the vote.
var myJSONObject = {"bindings": [{"ircEvent": "PRIVMSG", "Method": "New URI", "Reggae": "^ http: //.*"} , {"IrcEvent": "PRIVMSG", "Method": "DeleteERI", "Reggae": "^ Delete. *"}, {"IrcEvent": "PRIVMSG", "Law": This is the reason why I want to do that I want to structure my javascript according to a tree accordingly. The piece of code above is from JSON.org, I think I want 3 ircEvents of "binding" like structure, I do not know how to make it from backward (thanks to Javascript) Thanks
see the update below If you already have JavaScript stuff , Then use the JSON.stringify Douglas Crockford (provider of JSON) on it to get the equivalent JSON string in json2.js JSON.stringify is implemented. It is now manufactured in a growing number of browsers that it has been standardized, but many do not (too many), so we still have to use a utility script (Crockford or any other). The original, JSON is much easier than the object graph (which is one of the JSON's points, can be easily built and consumed).
JSON JavaScript Object is a subset of Little Notation. Then this javascript (not JSON) object: >
{"bindings": [{"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^ http: looks
Em> absolutely such as in JSON. If you want to put it inside a file If you were going in memory or from a server or whatever you read, if you were going to embed a JSON string inside the JavaScript code (maybe it's a strange thing to do, but ), You just lapsed in that quote "PRIVMSG", "Method": "New URI", "Reggae": "^ http: // http: //" bindings ":" '"{" IrcEvent ":" PRIVMSG " //.* "}, '+' {" ircEvent ":" PRIVMSG "," Method ":" DeleteEyeari "," Reggae ":" ^ Delete. * "} '+'] '+'} ';
If you were written without quotes without the JavaScript script's key, or you use single quotes, you It needs to be changed because JSON is specially given the key name and double quotation for all the stars. So this javascript object is really:
{foo: 'bar'} P> {"foo": "bar"}
Update : Give your comment below: Sorry, I asked this question Adding Javascript object origin / value (e.g., "map" or "dictionary" therefore: / / Start with a blank object obj = {}; // Add an address to it obj.foo = {}; // value 42 with obj.foo.subfoo = 42, add an address under the leaf; // root Add a new holiday for it; It has an array with 1, 2, and obj.bar = 3 [3, 3]; Alert (JSON.stringify (obj)); // '{} foo: { "Sifu": 42}, "Bar": [1, 2, 3]} ' You can write it as a literal, but I think you know that: < Pre> var obj = {foo: {subfoo: 42}, bar: [1, 2, 3]}; Do not you know that there may be variables in a verbatim right side, their value will be used, such as with assignments. So it gives me exactly the same obj as above: var charlatao = 42; Var obj = {foo: {subfoo: fortytwo}, bar: [1, 2, 3]};
Comments
Post a Comment