Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Directory (?) [+]
[HTML]View PlainCopy
- var str = {"Code": "", "Svcname": "", "Version": "", "Component": "", "category": "", "requestmsg": [{"FieldName": " UserName ', ' type ': ' Simple ', ' required ': ' True '},{' fieldName ': ' Age ', ' type ': ' Simple ', ' required ': ' True '}]}
First, check if the string is in JSON format:
[HTML]View PlainCopy
- function Isjsonformat (str) {
- try {
- $.parsejson (str);
- } catch (e) {
- return false;
- }
- return true;
- }
Format the JSON-formatted string output, first convert the JSON string to an object, and then format the object in JSON output:
[HTML]View PlainCopy
- Json.stringify (Json.parse (JSON), null, "\ T")
[HTML]View PlainCopy
- Json.stringify (Json.parse (JSON), NULL, 4)
Ps:\t: Represents indenting a tab;4: Represents the output formatted after indenting 4 spaces:
[HTML]View PlainCopy
- {
- "Code": "",
- "Svcname": "",
- "Version": "",
- "Component": "",
- "Category": "",
- "Requestmsg": [
- {
- "FieldName": "UserName",
- "Type": "Simple",
- "Required": "True"
- },
- {
- "FieldName": "Age",
- "Type": "Simple",
- "Required": "True"
- }
- ]
- }
Recommend a good JSON online parsing tool: http://www.json.cn/
Verifies whether a string is in JSON format and presents a regular presentation of a malformed JSON-formatted string (JSON formatted)