2011-09-24 66 views
1

我從Facebook上找到了這段代碼。我想以這種方式使用結構。我怎樣才能使用這種方法?使用Facebook上的JavaScript方法

for (;;);{"__ar":1,"payload":null,"css":["wOyD6","Dk+z9","uUZcv"],"js":["TNp9j","12BHN"],"onload":["(function(){var k=Arbiter.subscribe(\"xhpc\\\/construct\\\/\"+this.id,function(_,c){(function(){Arbiter.unsubscribe(k);}).defer();c.mutate({\"xhpc\":\"u598502_6\",\"endpoint\":\"\\\/ajax\\\/questions\\\/save.php\",\"formType\":1,\"inputHidden\":true,\"placeholder\":\"Bir \\u015fey sor...\",\"buttonLabel\":\"Payla\\u015f\",\"blurb\":\"\\u003ca class=\\\"addPollOptionsLink\\\" rel=\\\"async\\\" ajaxify=\\\"\\\/ajax\\\/questions\\\/show_poll_composer.php?xhpc_ismeta=true\\\">Anket \\u015e\\u0131klar\\u0131 Ekle\\u003c\\\/a>\",\"content\":\"\\u003cdiv class=\\\"webComposerQuestion\\\">\\u003cinput type=\\\"hidden\\\" autocomplete=\\\"off\\\" name=\\\"source\\\" value=\\\"composer\\\" \\\/>\\u003cdiv class=\\\"mas\\\">\\u003ctextarea class=\\\"DOMControl_placeholder uiTextareaNoResize uiTextareaAutogrow questionInput fluidInput\\\" title=\\\"Bir \\u015fey sor...\\\" spellcheck=\\\"true\\\" name=\\\"question\\\" maxlength=\\\"500\\\" placeholder=\\\"Bir \\u015fey sor...\\\" id=\\\"u614163_1\\\" onfocus=\\\"return wait_for_load(this, event, function() {if (!this._has_control) { new TextAreaControl(this).setAutogrow(true); this._has_control = true; } });\\\">Bir \\u015fey sor...\\u003c\\\/textarea>\\u003c\\\/div>\\u003c\\\/div>\",\"hideTopicTagger\":true});c.subscribe(\"init\", new Function(\"onloadRegister(function(){Input.enableAutoCapitalize($(\\\"u614163_1\\\"), \\\"\\\");});\\n\"));});;}).apply(DOM.find(this.getRelativeTo(),\"^div.uiComposer\"))"],"bootloadable":{"maxlength-form-listener":["LayX0","nO1QQ","12BHN"]},"resource_map":{"wOyD6":{"type":"css","src":"https:\/\/s-static.ak.facebook.com\/rsrc.php\/v1\/yC\/r\/Zg0ARUxUS6N.css"},"Dk+z9":{"type":"css","src":"https:\/\/s-static.ak.facebook.com\/rsrc.php\/v1\/yw\/r\/q4nJ2ZkJtyT.css"},"uUZcv":{"type":"css","permanent":1,"src":"https:\/\/s-static.ak.facebook.com\/rsrc.php\/v1\/yO\/r\/4okS7_KFNGX.css"},"TNp9j":{"type":"js","src":"https:\/\/s-static.ak.facebook.com\/rsrc.php\/v1\/yo\/r\/8rrAXwg5z80.js"},"12BHN":{"type":"js","src":"https:\/\/s-static.ak.facebook.com\/rsrc.php\/v1\/yg\/r\/jkR6Xtb9PGX.js"},"LayX0":{"type":"js","src":"https:\/\/s-static.ak.facebook.com\/rsrc.php\/v1\/yn\/r\/HT0e0kw4zvt.js"},"nO1QQ":{"type":"js","src":"https:\/\/s-static.ak.facebook.com\/rsrc.php\/v1\/y8\/r\/Cu4Eol99gUR.js"}}} 
+0

你能指定「這個方法」是什麼意思嗎? – harpo

+0

這是js代碼。我怎樣才能運行這段代碼。 –

+0

你從哪裏找到這種方法?你在找什麼? – apast

回答

5

目前尚不清楚你到底在問什麼。你不能「運行」這段代碼,它是一個JSON字符串。如果你想訪問數據,你需要以某種方式解析它,例如jquery中的parseJSON。

我懷疑你可能會被領先的for (;;);字符串絆倒。這是一個保護設備,防止人們僅僅使用eval()來處理數據。使用eval()是一種將JSON直接解析爲JavaScript變量的舊式快速骯髒方法,但這是一種不安全的做法。爲了防止Facebook將for循環代碼添加到字符串的前面,以便如果您嘗試評估它,您只會得到一個無限循環和一個掛起的瀏覽器。你當然可以從字符串中去掉那部分,然後使用eval,但是你更好地解析它。