how do parse this data string using json parser {"product": ["collection1", "collection2"]}
A:
- Please try and make complete sentences.
- This is an
object literal
not adata string
; data string would have to be"{\"product\":[\"collection1\",\"collection2\"]"
(it's actually of importance). - The method for
parsing
json strings, i.e. creating JSON objects from data strings, isJSON.parse()
in most browsers (except Opera), or$.parseJSON()
using jQuery.
Other than that, please elaborate on what you aim to do, so anyone can make their answers more fitting.
FK82
2010-05-10 14:06:21
hi fk82 i am requesting one url to response to that request i am getting this string(after converting from NSData. where product is key and collection1 and collection2 are values for that key. i want to get that value as collection1 and collection2 but i am getting braces around that values like "collection1" i want to remove that brace.
jeeva
2010-05-10 14:20:30
If the data you receive from your request is a `string`, you need to use `var myObject = JSON.parse( /* your string here */ )` to convert it into an `object`. Then you can access the `product` property as follows: `myObject["product"]` (`myObject["product"][0] ` for `collection1`; `myObject["product"][1] ` for `collection2`; ).
FK82
2010-05-10 16:37:49
thanks FK82.. i get that one that is parsing right i done mistake by checking in in-proper place...
jeeva
2010-05-11 04:49:45
If my comment helped you please rate it by clicking on the up arrow that appears next to it. Thanks!
FK82
2010-05-11 11:57:22