I am unable to create a Json string in the following format, please help. Where key value pair can be a number:
"tag_container": { "tag1": "Tag1", "tag2": "Tag2", ..... }
var uploaded = new Uploaded();
var str = "*#Hello* i *#am* writing a regexp *#h*";
var re = hash_parser(str);
uploaded.tag_list = new Array;
uploaded.tag_list.tag = new Array;
for(var i = 0; i < re.length; i++)
{
uploaded.tag_list[i] = new Object;
uploaded.tag_list[i].**tag** = re[i];
}
above code is giving in following format:
"tag_list":[{"**tag**":"*#Hello*"},{"**tag**":"*#am*"},{"**tag**":"*#h*"}]
string
at all. Second, what exactly is the problem with the output format?uploaded.tag_list = []
or like this:uploaded.tag_list = new Array()
. Likewise, objects are created like{}
ornew Object()
. You also seem confused about JSON. Did you want to wrap your JSON examples in single quotes? Like this:'"tag_container": { "tag1": "Tag1", "tag2": "Tag2", ..... }'
tag_list
to an object, and using this notation to enter key=>value pairs:uploaded.tag_list['tag' + (i+1)] = re[i];