Type of data
[{"id":"1","value":"Google"},{"id":"2","value":"Samsung"}]
Now I have a general function that performs certain actions based on the type of data being returned.
for this particular data I am checking if it is array or not. In order to check the type of the data being return I am using the following custom function.
function typeOf (obj) {
return {}.toString.call(obj).split(' ')[1].slice(0, -1).toLowerCase();
}
now if I call typeOf(1)
it returns "number" as answer
if I call typeOf("foo")
it return "string" as answer
The Problem
calling typeOf(data)
where data = [{"id":"1","value":"Google"},{"id":"2","value":"Samsung"}]
being echoed from php page it gives "string" as answer
It only returns array if the recieved array type data variable is passed through following function as
data = jQuery.parseJSON(data);
Now, I understand it might be the case that what ever gets echoed from php comes in string form but isn't there any way it can be changed as my php page is doing following
echo json_encode(array(array(some_key=>some_data)));