0

JSON 下面没有得到验证。我找不到问题

vartablearray=[
    {
        name: “Apple”,
        code: “APPL”,
        value: “111”,
        bid: “112”,
        offer: “110”
    },
    {
        name: “Microsoft”,
        code: “MSFT”,
        value: “78”,
        bid: “70”,
        offer: “75”
    },
    {
        name: “Google”,
        code: “GOGL”,
        value: “101”,
        bid: “98”,
        offer: “102”
    },
    {
        name: “Nokia”,
        code: “NOK”,
        value: “10”,
        bid: “8”,
        offer: “9”
    },
    {
        name: “Samsung”,
        code: “SAMS”,
        value: “89”,
        bid: “86”,
        offer: “90”
    },
    {
        name: “IntelCorporation”,
        code: “INTC”,
        value: “111”,
        bid: “112”,
        offer: “110”
    }
]
4

2 回答 2

3

JSON 要求密钥被双引号:

[{ "name": "Apple", ... }]

var tablearray=[ { name: “Apple” } ]也会导致 Javascript 中的语法错误,因为 javascript 不理解您正在使用的“花式”双引号,只有 ASCII 集中的“普通”双引号:var tablearray=[ { name: "Apple" } ]var tablearray=[ { "name": "Apple" } ]

于 2012-11-11T07:58:05.887 回答
1

尝试这个 var tablearray= jQuery.parseJSON('[ { "name": "Apple", "code": "APPL", "value": "111", "bid": "112", "offer": "110" }, { "name": "Microsoft", "code": "MSFT", "value": "78", "bid": "70", "offer": "75" }, { "name": "Google", "code": "GOGL", "value": "101", "bid": "98", "offer": "102" }, { "name": "Nokia", "code": "NOK", "value": "10", "bid": "8", "offer": "9" }, { "name": "Samsung", "code": "SAMS", "value": "89", "bid": "86", "offer": "90" }, { "name": "IntelCorporation", "code": "INTC", "value": "111", "bid": "112", "offer": "110" } ]');

于 2012-11-11T07:55:51.113 回答