0

I currently have a JSON file with the following data:

   {
   "user":"me",
   "payment_method":"card",
   "items_bought":[
      {
         "id":"001",
         "name":"desk",
         "delivered":"false"
      },
      {
         "id":"455",
         "name":"chair",
         "delivered":"false"
      },
      {
         "id":"234",
         "name":"mouse pad",
         "delivered":"false"
      },
      {
         "id":"135",
         "name":"cabinet",
         "delivered":"false"
      }
   ]
}

I wanna parse through the "items_bought" so i could get the name of each item in the array.

I am currently using this code to read my JSON file. I just need help for the loop so i could get the member or the array.

jsonString = File.ReadAllText(Application.dataPath + "/account_response.json");
jsonMessage = JsonMapper.ToObject(jsonString);
Debug.Log(jsonMessage["user"].ToString()); //prints value of user
Debug.Log(jsonMessage["payment_method"].ToString()); //prints value of payment_method

Any heads up would be much appreciated. Thanks.

3
  • 2
    Your json is not valid. When you fix it, see duplicate for how to de-serialize json array Commented Dec 13, 2017 at 6:29
  • you may also see stackoverflow.com/questions/13469666/… Commented Dec 13, 2017 at 6:59
  • 1
    @rudolf_franek thanks! that solved my problem. i was hoping i could find a solution that doesnt involve de-serializing Commented Dec 13, 2017 at 7:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.