Don't use string concatenation for JSON string, use JSON.stringify()


As javascript newbie, this is what I did.

[sourcecode language="javascript"]

return '{"Data" : '
+ '{'
+ '"uid" : "' + this.uid + '", '
+ '"approval" : "' + ($('.date-picker', this.form).val() || '') + '", '
+ '"count" : ' + this.uploader.getcount() + ', '
+ '"size" : ' + this.getsize() + ', '
+ '"fid" : ' + vm.getfid() + ', '
+ '"Notifees" : [], '
+ '"Assignees" : [], '
+ '"AssigneesPersonalMessage" : "", '
+ '"NotificationPersonalMessage" : "", '
+ '"TeamId" : 0, '
+ '"Addresses" : ""'
+ '}'
+ '}';
[/sourcecode]

But don't do this. You can use JSON.stringify(). it converts an object to JSON notation representing it.

With that, the code changes to this.

[sourcecode language="javascript"]
var metaData = {
"Data" : {
"uid" : self.uid,
"count" : 1,
"size" : self.getsize(),
"fid" : vm.getfid(),
"approval" : "",
"Notifees" : [],
"Assignees" : [],
"AssigneesPersonalMessage" : "",
"NotificationPersonalMessage" : "",
"TeamId" : 0,
"Addresses" : ""
}
};

return JSON.stringify(metaData);

[/sourcecode]