Search code examples
jqueryjsongetjson

I want to get value from my json by field name


I'm working with this json data, but the problem is that I want to get one of the field "sz_price" from this list. I found code from the internet that's supposed to be valid for this action but I still don't understand the method to get a single value. I don't want to use any loop, I just have a single field I want.

{"label":"4mm","sz_stock":"","sz_price":"50","sz_id":"6","count":1}]

$.getJSON("check.php", function(result){
            $.each(result, function(i, field){
                $("div").append(field + " ");
            });
        });

Solution

  • You should use this instead the loop:

    $("div").append(result["sz_price"]);