javascript - JSON parsing not working in jQuery -
i have text field id search_json on form contains:
{"standard_id":"2","attribute1":["","stan"],"attribute2":[""],"attribute3":["","air force"],"attribute4":["","bob"],"selected_index":3} upon event, call button click, want to:
1) read in json , parse object:
search_json = $.parsejson($("#search_json").val()) 2) remove "attribute1" object
delete search_json["attribute1"] 3) write json out text field:
$("#search_json").val(json.stringify(search_json)) i'm kind of surprised it's not working, though. delete call nothing. matter of fact,
search_json.hasownproperty("attribute1") returns false. , yet can log object console , indeed object values. going wrong here?
update: actually,
search_json.hasownproperty("attribute1") does work. but, if attribute name text field, so:
attribute_name = $("#attribute_name").attr("id") and:
console.log attribute_name shows "attribute1", not work:
search_json.hasownproperty(attribute_name) returns false. mystifying.
i don't it. i'm using fiddle code , correct
the final object is:
attribute2: array[1] attribute3: array[2] attribute4: array[2] selected_index: 3 standard_id: "2" attribute1 delete correclty
Comments
Post a Comment