views:

54

answers:

1

how do parse this data string using json parser {"product": ["collection1", "collection2"]}

A: 
  1. Please try and make complete sentences.
  2. This is an object literal not a data string; data string would have to be "{\"product\":[\"collection1\",\"collection2\"]" (it's actually of importance).
  3. The method for parsing json strings, i.e. creating JSON objects from data strings, is JSON.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
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
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
thanks FK82.. i get that one that is parsing right i done mistake by checking in in-proper place...
jeeva
If my comment helped you please rate it by clicking on the up arrow that appears next to it. Thanks!
FK82

related questions