1

I am trying to parse this json in angular js using ngrepeat but it is not giving length. Can anybody please tell me how to parse this json

{
  "item1": {
    "timing": "9:15-12:30,15:00-21:15,13:00-14:30",
    "price": 45,
    "session": "breakfast",
    "check": false
  },
  "item2": {
    "timing": "10:15-12:30,15:00-18:15",
    "price": 55,
    "session": "breakfast",
    "check": true
  },
  "item3": {
    "timing": "15:00-18:15",
    "price": 25,
    "session": "snacks",
    "check": true

  }

}

UPDATE

<div ng-repeat="tempdata in jsonData">
<div>{{tempdata.timing}}
</div>
<div>{{tempdata.price}}
</div>
....
</div>

I am trying to achieve through ng-repeat but i got stuck Regards

7
  • You are trying how? Please show your code. You have an object and objects have no length (arrays do) and the ng-repeat docs show you how to repeat an object Commented May 24, 2016 at 2:37
  • @charlietfl Can u please post a link which explains it? Commented May 24, 2016 at 2:42
  • Can you please show your approach with code? Commented May 24, 2016 at 2:44
  • @NutBoltu I updated my code. Please check Commented May 24, 2016 at 2:51
  • @Kumar You are running ng-repeat over a key-value object. Your json data is not an array. So you need to use key value to retrieve the data. Please see my answer. Commented May 24, 2016 at 3:00

2 Answers 2

1

You are probably trying to do something like this.

<div ng-repeat="(key,val) in jsonData">
  <p>{{jsonData[key]["timing"]}}</p>
  <p>{{{jsonData[key]["price"]}}</p>
</div>

If you are making an http request to receive your json data, remember that the angular http service returns a promise and you will need to handle that before adding the data to the scope.

Sign up to request clarification or add additional context in comments.

Comments

0

You are running ng-repeat over a key-value object. Your json data is not an array. So you need to use key value to retrieve the data.

<div ng-repeat="(key,value) in jsonData">
     <div>{{jsonData[key].timing}}
     </div>
    <div>{{jsonData[key].price}}
    </div>
    ....
</div>

and also jsonData has no length as it is an object.

2 Comments

@NutBoltuThanks for response
If my answer helps you please upvote it or make it right answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.