0

我在表单中有 JSON 字符串

  [
    {
        "couponcode": "HOMEV300JF",
        "source": "a",
        "description": "Rs 300 OFF on Home and Furniture section, on a minimum purchase of 1499 and above. Applicable on products..."
    },
    {
        "couponcode": "MENSP10PMA",
        "source": "a",
        "description": "Upto 50% off + Add 10% off on Rs.999"
    },
    {
        "couponcode": "MOVIE1000",
        "source": "a",
        "description": "Shop For Rs. 1999 & Above & Get 4 Movie Tickets Free Worth Rs. 1000 For Free"
    },
    {
        "couponcode": "SALE15",
        "source": "a",
        "description": "Get upto 75% off + Additional 15% off on Rs.2499"
    },
    {
        "couponcode": "SALE25",
        "source": "a",
        "description": "Get upto 75% off + Additional 25% off on Rs.2499"
    }
]

我想将此 JSON (casperJS) 转换为一个对象,以便我可以像访问对象一样访问它

var length = object.length

4

1 回答 1

0

@Brad 是正确的,这是您的(他的略微修改的版本)答案:

var TempName = JSON.parse('[{"couponcode": "HOMEV300JF", "source": "a", "description": "Rs 300 OFF on Home and Furniture section, on a minimum purchase of 1499 and above. Applicable on products..."}, {"couponcode": "MENSP10PMA", "source": "a", "description": "Upto 50% off + Add 10% off on Rs.999"}, {"couponcode": "MOVIE1000", "source": "a", "description": "Shop For Rs. 1999 & Above & Get 4 Movie Tickets Free Worth Rs. 1000 For Free"}, {"couponcode": "SALE15", "source": "a", "description": "Get upto 75% off + Additional 15% off on Rs.2499"}, {"couponcode": "SALE25", "source": "a", "description": "Get upto 75% off + Additional 25% off on Rs.2499"}]');

var length = TempName.length;

console.log(length); // see it...
于 2013-08-11T21:26:41.737 回答