-1

I have this Json

var data = "{"2144":{"quantity":"350"},"2095":{"quantity":"100"}}"

how can i get each value like this order using jquery?

2144 - quantity:350 2095 - quantity:100

Fray
  • 250
  • 2
  • 5
  • 16
  • You will want to start by converting the `data` string into a json object. See [this answer](https://stackoverflow.com/a/5686237/3586783) to get you started. Then, you will basically be iterating through the json object keys and printing the key and value. – pacifier21 Jun 05 '17 at 21:53

1 Answers1

0

Loop through each key/value pair in nested format like this:

 var data = JSON.parse( '{"2144":{"quantity":"350"},"2095":    {"quantity":"100"}}');

    $.each(data , function(key , value){
     $.each(value , function(k , v ){
         console.log(key + '-' + k + ':' + v)
     });  
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
adhikari18
  • 165
  • 2
  • 11