Mercurial > pub > ImplabNet
comparison Implab/JSON/JSONWriter.cs @ 141:0fa293bb1351 v2
fixed JSON writer
author | cin |
---|---|
date | Tue, 24 Feb 2015 00:54:22 +0300 |
parents | 2573b562e328 |
children | 2100965eb97f |
comparison
equal
deleted
inserted
replaced
140:f973c5df9972 | 141:0fa293bb1351 |
---|---|
85 WriteMemberName(name); | 85 WriteMemberName(name); |
86 Write(value); | 86 Write(value); |
87 } | 87 } |
88 | 88 |
89 public void WriteValue(string value) { | 89 public void WriteValue(string value) { |
90 if (m_context.element != JSONElementContext.Array) | 90 if (m_context.element == JSONElementContext.Array) { |
91 | |
92 if (m_context.needComma) | |
93 m_writer.Write(","); | |
94 WriteIndent(); | |
95 m_context.needComma = true; | |
96 | |
97 Write(value); | |
98 } else if (m_context.element == JSONElementContext.None) { | |
99 Write(value); | |
100 m_context.element = JSONElementContext.Closed; | |
101 } else { | |
91 OperationNotApplicable("WriteValue"); | 102 OperationNotApplicable("WriteValue"); |
92 if (m_context.needComma) | 103 } |
93 m_writer.Write(","); | |
94 WriteIndent(); | |
95 m_context.needComma = true; | |
96 | |
97 Write(value); | |
98 } | 104 } |
99 | 105 |
100 public void WriteValue(bool value) { | 106 public void WriteValue(bool value) { |
101 if (m_context.element != JSONElementContext.Array) | 107 if (m_context.element == JSONElementContext.Array) { |
108 | |
109 if (m_context.needComma) | |
110 m_writer.Write(","); | |
111 WriteIndent(); | |
112 m_context.needComma = true; | |
113 | |
114 Write(value); | |
115 } else if (m_context.element == JSONElementContext.None) { | |
116 Write(value); | |
117 m_context.element = JSONElementContext.Closed; | |
118 } else { | |
102 OperationNotApplicable("WriteValue"); | 119 OperationNotApplicable("WriteValue"); |
103 if (m_context.needComma) | 120 } |
104 m_writer.Write(","); | |
105 m_context.needComma = true; | |
106 | |
107 WriteIndent(); | |
108 Write(value); | |
109 } | 121 } |
110 | 122 |
111 public void WriteValue(double value) { | 123 public void WriteValue(double value) { |
112 if (m_context.element != JSONElementContext.Array) | 124 if (m_context.element == JSONElementContext.Array) { |
125 | |
126 if (m_context.needComma) | |
127 m_writer.Write(","); | |
128 WriteIndent(); | |
129 m_context.needComma = true; | |
130 | |
131 Write(value); | |
132 } else if (m_context.element == JSONElementContext.None) { | |
133 Write(value); | |
134 m_context.element = JSONElementContext.Closed; | |
135 } else { | |
113 OperationNotApplicable("WriteValue"); | 136 OperationNotApplicable("WriteValue"); |
114 if (m_context.needComma) | 137 } |
115 m_writer.Write(","); | |
116 m_context.needComma = true; | |
117 | |
118 WriteIndent(); | |
119 Write(value); | |
120 } | 138 } |
121 | 139 |
122 public void BeginObject() { | 140 public void BeginObject() { |
123 if (m_context.element != JSONElementContext.None && m_context.element != JSONElementContext.Array) | 141 if (m_context.element != JSONElementContext.None && m_context.element != JSONElementContext.Array) |
124 OperationNotApplicable("BeginObject"); | 142 OperationNotApplicable("BeginObject"); |
144 m_writer.Write("{"); | 162 m_writer.Write("{"); |
145 } | 163 } |
146 | 164 |
147 public void EndObject() { | 165 public void EndObject() { |
148 if (m_context.element != JSONElementContext.Object) | 166 if (m_context.element != JSONElementContext.Object) |
149 OperationNotApplicable("EndArray"); | 167 OperationNotApplicable("EndObject"); |
150 | 168 |
151 m_context = m_contextStack.Pop(); | 169 m_context = m_contextStack.Pop(); |
170 if (m_contextStack.Count == 0) | |
171 m_context.element = JSONElementContext.Closed; | |
152 WriteIndent(); | 172 WriteIndent(); |
153 m_writer.Write("}"); | 173 m_writer.Write("}"); |
154 } | 174 } |
155 | 175 |
156 public void BeginArray() { | 176 public void BeginArray() { |
180 public void EndArray() { | 200 public void EndArray() { |
181 if (m_context.element != JSONElementContext.Array) | 201 if (m_context.element != JSONElementContext.Array) |
182 OperationNotApplicable("EndArray"); | 202 OperationNotApplicable("EndArray"); |
183 | 203 |
184 m_context = m_contextStack.Pop(); | 204 m_context = m_contextStack.Pop(); |
205 if (m_contextStack.Count == 0) | |
206 m_context.element = JSONElementContext.Closed; | |
185 WriteIndent(); | 207 WriteIndent(); |
186 m_writer.Write("]"); | 208 m_writer.Write("]"); |
187 } | 209 } |
188 | 210 |
189 void Write(bool value) { | 211 void Write(bool value) { |