Monday, April 27, 2009

[jQuery] Re: how to convert a string to json structure

gaohk wrote:
> I have a string that is like [{"carePacks":
> [{"businessCode":"J1PS","description":"HP 1"}],"coveragePeriod":12},
> {"carePacks":[{"businessCode":"J1PS","description":"HP
> s"}],"coveragePeriod":13}].
> can you give me some advice on how to convert it to a json structure,
> and how to get data from the data structure, like get "HP 1".

This doesn't require any jQuery work, although jQuery might help you
fetch the data.

var items = eval('(' + data + ')');
alert(items[0]["carePacks"][0]["description"]);

Cheers,

-- Scott

No comments:

Post a Comment