-2

Hi Is there any other way I can eval json string.

My example:

var json='[{ data: {id:"oxid"},group:"nodes"},{ data: {id:"e40", source:"HK1",target:"oxid"},group:"edges"},{ data: {id:"skeletal muscles"},group:"nodes"},{ data: {id:"e41", source:"HK1",target:"skeletal muscles"},group:"edges"},{ data: {id:"atp"},group:"nodes"},{ data: {id:"e42", source:"HK1",target:"atp"},group:"edges"},{ data: {id:"mitochondria"},group:"nodes"},{ data: {id:"e43", source:"HK1",target:"mitochondria"},group:"edges"},{ data: {id:"mitochondrial"},group:"nodes"},{ data: {id:"e44", source:"HK1",target:"mitochondrial"},group:"edges"},{ data: {id:"metabolism"},group:"nodes"},{ data: {id:"e45", source:"HK1",target:"metabolism"},group:"edges"},{ data: {id:"rat"},group:"nodes"},{ data: {id:"e46", source:"HK1",target:"rat"},group:"edges"},{ data: {id:"binding"},group:"nodes"},{ data: {id:"e47", source:"HK1",target:"binding"},group:"edges"},{ data: {id:"HK1"},group:"nodes"},]';

It seems I can not use JSON.parse() or jQery.parseJSON() to evaluate it, there is error there. Thanks.

update: the string is created by my program automatically, I use javascript to concatenate several string variable to get variable json. The json string is not hard coding one. Actually, I can use eval(json), it's working, but I heard it's dangerous to use eval() in my javascript.

4

1 回答 1

1

如果您使用 JavaScript,请在​​ JavaScript IE Java Script Object Notation 中构造对象:

var myJson = [];

myJson.push({
    data: {id:"oxid"},
    group:"nodes"
});
于 2013-10-30T21:23:58.090 回答