I have a JSON string(?) that I have returned from $.ajax() and named it data. Some of the values are empty and I need to add values to some of the keys and send it back to my PHP script.
I access the existing values by data.keyName. How do I add or change the values of certain keys in data?
This is what data looks like.
{     "ID":"48",     "userID":"0",     "address":"750 North High Street",     "city":"Columbus",     "state":"OH",     "zip":"43215",     "lat":"39.977673",     "lng":"-83.003357",     "busNumber":"55",     "isClaimed":"N",     "whereFound":"",     "busNum":"",     "email":"",     "fname":"",     "lname":"",     "comments":"" }   
                Once you have decoded the JSON, the result is a JavaScript object. Just manipulate it as you would any other object. For example:
data.busNum = 12345; ... 
                        var temp = data.oldKey; // or data['oldKey'] data.newKey = temp; delete data.oldKey; 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With