jquery Anzeige formatiert json

Hallo ich habe ein problem denn mein json ist nicht die Anzeige als formatierten json.

in meiner web-Seite habe ich ein <pre></pre> tag, es cointains json-string:

json-Beispiel:

{"status": "OK", "output": {"pools": [{"stats": {"bytes_used": 0, "objects": 0, "kb_used": 0}, "name": "data", "id": 0}, {"stats": {"bytes_used": 0, "objects": 0, "kb_used": 0}, "name": "metadata", "id": 1}, {"stats": {"bytes_used": 0, "objects": 0, "kb_used": 0}, "name": "rbd", "id": 2}], "stats": {"total_used": 63330648, "total_space": 125604864, "total_avail": 62274216}}}

verwende ich jquery-Skript zu formatieren:

var jsonPretty = JSON.stringify($(this).text(), null, '\t');
$(this).text(jsonPretty);

aber itsn nicht arbeiten, das Ergebnis ist:

"{\"status\": \"OK\", \"output\": {\"pools\": [{\"stats\": {\"bytes_used\": 0, \"objects\": 0, \"kb_used\": 0}, \"name\": \"data\", \"id\": 0}, {\"stats\": {\"bytes_used\": 0, \"objects\": 0, \"kb_used\": 0}, \"name\": \"metadata\", \"id\": 1}, {\"stats\": {\"bytes_used\": 0, \"objects\": 0, \"kb_used\": 0}, \"name\": \"rbd\", \"id\": 2}], \"stats\": {\"total_used\": 63330648, \"total_space\": 125604864, \"total_avail\": 62274216}}}"

wie kann ich es formatieren, um die Anzeige schön formatierte json ?

InformationsquelleAutor Vardius | 2014-02-18

Schreibe einen Kommentar