my script is getting some array from php server side script.
result = jQuery.parseJSON(result);
现在我想判断数组的每个变量.
if (result.a!='') { something.... }
if (result.b!='') { something.... }
....
有没有更好的方法让它像php中的‘foreach’、‘while’或smth那样更快呢?
UPDATE个
This code ( thanks to hvgotcodes ) gives me values of variables inside the array but how can I get the names of variables also ?
for(var k in result) {
alert(result[k]);
}
UPDATE 2
这就是php端的工作原理
$json = json_encode(array("a" => "test", "b" => "test", "c" => "test", "d" => "test"));