There are times when you need to save the data in your interface, and it's convenient to use a JSON string.
In the app development network request this piece, has been converted to been file way so far, cannot get the original JSON string, needs to construct itself.
In practice, it is found that when the key value is constructed, the key is formatted with "", string value, such as: "\" client\ ": \" "+ client +" \ "+" + ", and the value" "format causes parsing to fail.
Perform ALT + Intert in as Java code, select ToString () display:
The default template is Concat (+).
Create a new template in the settings named Tojson.
Copy the template from Concat (+) to the new template and change it to a JSON template.
The template contents are as follows:
Public java.lang.String toString () {
#if ($members. Size () > 0)
#set ($i = 0)
Return "{" +
#foreach ($member in $members)
#if ($i = 0)
"##
#else
", ##
#end
#if ($member. Objectarray)
#if ($java _version < 5)
\ "$member. Name\": "+ ($member. accessor = null?) Null:java.util.Arrays.asList ($member. Accessor)) +
#else
\ "$member. Name\": "+ java.util.Arrays.toString ($member. Accessor) +
#end
#elseif ($member. Primitivearray && $java _version >= 5)
\ "$member. Name\": "+ java.util.Arrays.toString ($member. Accessor) +
#elseif ($member. String)
\ "$member. Name\": \ "" + $member. Accessor + "\" +
#else
\ "$member. Name\": "+ $member. Accessor +
#end
#set ($i = $i + 1)
#end
'}';
#else
Return "$classname {}";
#end
}