If the string is in javascript, there are the two ways already
mentioned, though if you built the string in javascript you should
probably just build the json object instead.  If the string is in PHP/
JSP/or some other server side language, then just print it out into
the javascipt and save it into a variable.

<script>
var foo = <%= jsonString %>
</script>

To get data from the object, just use normal object and array
references as if it were any other object/array:

foo[0].carePacks[0].description

On Apr 27, 6:06 am, Remon Oldenbeuving <r.s.oldenbeuv...@gmail.com>
wrote:
> You could also use:
>
> var myobj = (new Function("return " + JSONString))()
>
> http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comme...
>
> On Mon, Apr 27, 2009 at 2:30 PM, Remon Oldenbeuving <
>
> r.s.oldenbeuv...@gmail.com> wrote:
> > If your completly sure that it is save, you could just use eval:
>
> > eval("var myJSON = [{"carePacks": [{"businessCode":"J1PS","description":"HP
> > 1"}],"coveragePeriod":12},{"carePacks":[{"businessCode":"J1PS","description":"HP
> > s"}],"coveragePeriod":13}];");
>
> > On Mon, Apr 27, 2009 at 10:13 AM, gaohk <cnga...@gmail.com> 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".
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to