json objects and TypeError: Cannot use 'in' operator to search for 'length'

Subject:

sometimes when sending json_encode() back from php I will get an erorr

TypeError: Cannot use 'in' operator to search for 'length'

meaning it is a string and I need to use JSON.pase()

ex.            $.each(JSON.parse(data), function(name, value){                    console.log(name);                });

the above was for a result of {"success":true,"template":null}

2016-10-03 13:24:14gstlouis

                $.each(JSON.parse(data), function(name, value){
                    console.log(name);
                });

gstlouis
vote
2016-10-03 13:25:10

from what I can see, if there are no data inside the json there is no data objects to loop into so you have to use JSON.parse() with the top level results 

gstlouis
vote
2016-10-03 13:26:38