-1

Hi I have a json response that I have to parse. I want to pull the data and insert it into inputs value (if it exists)

My json is like this:

{"id":4,"comb_name":"Monitor__C9cGTqnM7Trz","resolution":null,"attribute_val":3,"porte":4, "deleted_at":null,"created_at":"2017-11-13 10:10:25","updated_at":"2017-11-13 10:10:25"}

The code:

    if(isset(jsobj)) {
        var parsed = JSON.parse(jsobj);
        console.log(parsed);
        for (var property in parsed) {
            if(parsed.hasOwnProperty(property)) {
                var possible_input = '#pro_' + property;
                if($(possible_input).length) {
                    var actual_input = $(possible_input);
                    actual_input.val(property);
                }
            }
        }
    }

It actually works, the only problem is that "property" are "attribute_val", not "3". What can I do to grab the value of the property?

  • parsed[property] –  Nov 13 '17 at 11:10
  • Possible duplicate of [Access / process (nested) objects, arrays or JSON](https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – Liam Nov 13 '17 at 11:12

1 Answers1

0

Just use the property name to access the value actual_input.val(parsed[property]);

Joschi
  • 2,874
  • 1
  • 18
  • 23