comparison src/luan/lib/json/JsonToString.java @ 1116:633ca24d4d6e

fix JsonToString
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 04 Aug 2017 11:06:08 -0600
parents 809d74db1415
children 9a1aa6fc0b4e
comparison
equal deleted inserted replaced
1115:809d74db1415 1116:633ca24d4d6e
71 } 71 }
72 sb.append('"'); 72 sb.append('"');
73 } 73 }
74 74
75 private static void toString(List list,StringBuilder sb) { 75 private static void toString(List list,StringBuilder sb) {
76 if( list.isEmpty() ) {
77 sb.append("{}");
78 return;
79 }
80 sb.append('['); 76 sb.append('[');
81 toString(list.get(0),sb); 77 if( !list.isEmpty() ) {
82 for( int i=1; i<list.size(); i++ ) { 78 toString(list.get(0),sb);
83 sb.append(','); 79 for( int i=1; i<list.size(); i++ ) {
84 toString(list.get(i),sb); 80 sb.append(',');
81 toString(list.get(i),sb);
82 }
85 } 83 }
86 sb.append(']'); 84 sb.append(']');
87 return; 85 return;
88 } 86 }
89 87
90 private static void toString(Map map,StringBuilder sb) throws JsonException { 88 private static void toString(Map map,StringBuilder sb) throws JsonException {
91 sb.append('{'); 89 sb.append('{');
92 Iterator<Map.Entry> i = map.entrySet().iterator(); 90 if( !map.isEmpty() ) {
93 toString(i.next(),sb); 91 Iterator<Map.Entry> i = map.entrySet().iterator();
94 while( i.hasNext() ) {
95 sb.append(',');
96 toString(i.next(),sb); 92 toString(i.next(),sb);
93 while( i.hasNext() ) {
94 sb.append(',');
95 toString(i.next(),sb);
96 }
97 } 97 }
98 sb.append('}'); 98 sb.append('}');
99 } 99 }
100 100
101 private static void toString(Map.Entry entry,StringBuilder sb) throws JsonException { 101 private static void toString(Map.Entry entry,StringBuilder sb) throws JsonException {
133 sb.append('\t'); 133 sb.append('\t');
134 } 134 }
135 } 135 }
136 136
137 private static void toString(List list,StringBuilder sb,int indented) { 137 private static void toString(List list,StringBuilder sb,int indented) {
138 if( list.isEmpty() ) { 138 sb.append('[');
139 sb.append("{}"); 139 if( !list.isEmpty() ) {
140 return; 140 indent(sb,indented+1);
141 toString(list.get(0),sb,indented+1);
142 for( int i=1; i<list.size(); i++ ) {
143 sb.append(',');
144 indent(sb,indented+1);
145 toString(list.get(i),sb,indented+1);
146 }
147 indent(sb,indented);
141 } 148 }
142 sb.append('[');
143 indent(sb,indented+1);
144 toString(list.get(0),sb,indented+1);
145 for( int i=1; i<list.size(); i++ ) {
146 sb.append(',');
147 indent(sb,indented+1);
148 toString(list.get(i),sb,indented+1);
149 }
150 indent(sb,indented);
151 sb.append(']'); 149 sb.append(']');
152 return; 150 return;
153 } 151 }
154 152
155 private static void toString(Map map,StringBuilder sb,int indented) throws JsonException { 153 private static void toString(Map map,StringBuilder sb,int indented) throws JsonException {
156 sb.append('{'); 154 sb.append('{');
157 Iterator<Map.Entry> i = map.entrySet().iterator(); 155 if( !map.isEmpty() ) {
158 indent(sb,indented+1); 156 Iterator<Map.Entry> i = map.entrySet().iterator();
159 toString(i.next(),sb,indented+1);
160 while( i.hasNext() ) {
161 sb.append(',');
162 indent(sb,indented+1); 157 indent(sb,indented+1);
163 toString(i.next(),sb,indented+1); 158 toString(i.next(),sb,indented+1);
159 while( i.hasNext() ) {
160 sb.append(',');
161 indent(sb,indented+1);
162 toString(i.next(),sb,indented+1);
163 }
164 indent(sb,indented);
164 } 165 }
165 indent(sb,indented);
166 sb.append('}'); 166 sb.append('}');
167 } 167 }
168 168
169 private static void toString(Map.Entry entry,StringBuilder sb,int indented) throws JsonException { 169 private static void toString(Map.Entry entry,StringBuilder sb,int indented) throws JsonException {
170 Object key = entry.getKey(); 170 Object key = entry.getKey();