2
我想將格式化的json字符串添加到我的textarea字段。但它不起作用。 How can I beautify JSON programmatically?帶格式的ExtJs textarea
,然後就打電話
textarea.setValue(formattedJson);
檢查結果的快照:
我用這個方法格式化字符串
是否poosible正確地得到在textarea格式化的字符串?
我想將格式化的json字符串添加到我的textarea字段。但它不起作用。 How can I beautify JSON programmatically?帶格式的ExtJs textarea
,然後就打電話
textarea.setValue(formattedJson);
檢查結果的快照:
我用這個方法格式化字符串
是否poosible正確地得到在textarea格式化的字符串?
JSON.stringify
方法需要對象作爲參數。您可能會發送字符串作爲參數。這是正確的代碼:
jsonObj = {a: 'b', c: [1,2,3]};
// note that jsonObj is object, not string
jsonString = JSON.stringify(jsonObj, null, '\t');
textarea.setValue(jsonString);
這裏是jsfiddle
哇!酷,正是我需要的。謝謝 – 2012-02-08 09:56:08