pig's diary

何でも忘れるので万年初心者ね

print_r

これ便利ですなあ。
http://labs.unoh.net/2006/11/javascript.html
firebugいつも使うから、consoleオブジェクトのメソッドにでもしてもらいたい気分になりますなあ。

function print_r(obj) {
var count_obj = 0,
    result = '';
    function _output(str) {
       // document.writeln(str + "<br/>");
       result += str + "<br/>";
    }
    function _print_r(obj, name, level) {
     var s = "";
        if (obj == undefined || level > 4) return;
        for (var i = 0; i < level; i++) { s += " | "; }
        s += " - " + name + ":" + typeof(obj) + "=" + obj;
        _output(s);
        if (name == "document" || typeof(obj) != "object") return;
        for ( key in obj ) {
        if (count_obj++ > 150) return;
         _print_r(obj[key], key, level + 1);
        }
    }
   _print_r(obj, "*", 0);
   
   return result;
}
$.ajax({
  type: "GET",
  url: "",
  data: {
  	callback: 'yeah'
  },
  dataType: "jsonp"
});
$.getJSON(
	"http://search.twitter.com/search.json?callback=?",
	{q:'twitter'},
	function(json){
  	alert(print_r(json));
	}
);