为什么我的jsondata对象未定义?

时间:2014-09-09 17:32:11

标签: javascript jquery json javascript-objects

var jsondata = $.parseJSON('{"bwpaperback":{"creme":{"5x8":[".95",".016"],"5_25x8":[".95",".016"],"5_5x8_5":[".95",".016"],"6x9":[".95",".016"],"pages":["18","1050"]},"white":{"5x8":[".95",".016"],"5_25x8":[".95",".016"],"5_5x8_5":[".95",".016"],"6x9":[".95",".016"],"8x8":[".95",".016"],"8_5x8_5":[".95",".016"],"7x10":["1.35",".021"],"8x10":["1.35",".021"],"8_25x11":["1.35",".021"],"8_5x11":["1.35",".021"],"pages":["18","1200"]}},"bwhardcover":{"case":{"creme":{"5x8":["6.05",".016"],"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"pages":["18","1050"]},"white":{"5x8":["6.05",".016"],"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"8x8":["6.05",".016"],"8_5x8_5":["6.05",".016"],"7x10":["6.05",".021"],"8x10":["6.05",".021"],"8_5x11":["6.05",".021"],"pages":["18","1200"]}},"cloth":{"creme":{"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"pages":["18","1050"]},"white":{"5x8":["6.05",".016"],"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"pages":["18","1200"]}}},"scpaperback":{"5x7":[".95",".026"],"5x8":[".95",".026"],"5_25x8":[".95",".026"],"5_5x8_5":[".95",".026"],"6x9":[".95",".026"],"8_5x8)5":[".95",".026"],"7x10":["1.30",".031"],"8x10":["1.30",".031"],"8_25x11":["1.30",".031"],"8_5x11":["1.30",".031"],"pages":["18","1200"]},"schardcover":{"case":{"5x8":["6.05",".026"],"5_5x8_5":["6.05",".026"],"6x9":["6.05",".026"],"8x8":["6.05",".026"],"8_5x8_5":["6.05",".026"],"7x10":["6.05",".031"],"8x10":["6.05",".031"],"8.5x11":["6.05",".031"],"pages":["18","1200"]},"cloth":{"5x8":["6.05",".026"],"5_5x8_5":["6.05",".026"],"6x9":["6.05",".026"],"pages":["18","1200"]}},"pcpaperback":{"5_5x8_5":["1.05",".06"],"6x9":["1.05",".09"],"8x8":["1.05",".09"],"8_5x8_5":["1.05",".09"],"7x10":["1.55",".10"],"8x10":["1.55",".10"],"8_5x11":["1.55",".10"],"pages":["4,900"]},"pchardcover":{"case":{"5x8":["6.05",".06"],"5_5x8_5":["6.05",".06"],"6x9":["6.05",".091"],"8x8":["6.05",".091"],"8_5x8_5":["6.05",".091"],"7x10":["6.05",".011"],"8x10":["6.05",".011"],"8_5x11":["6.05",".011"],"pages":["24,840"]},"cloth":{"5x8":["6.05",".06"],"5_5x8_5":["6.05",".06"],"6x9":["6.05",".091"],"pages":["24,840"]}}}');

        if(main.hasClass('bw') && main.hasClass('paperback')){
            baseprice = jsondata[calctype][color][size][0];
            perpage = jsondata[calctype][color][size][1];
            minpages = jsondata[calctype][color].pages[0];
            maxpages = jsondata[calctype][color].pages[1];
        }

我不确定是否需要提供更多代码。但它说“未捕获的TypeError:无法读取未定义的属性'#'”

当我从外部json文件使用$ .getJSON时,这个工作正常。我怎样才能将它用作对象而不是.json?

谢谢!

0 个答案:

没有答案