Show More
@@ -230,15 +230,11 b' def json(obj):' | |||||
230 | elif isinstance(obj, str): |
|
230 | elif isinstance(obj, str): | |
231 | return '"%s"' % encoding.jsonescape(obj, paranoid=True) |
|
231 | return '"%s"' % encoding.jsonescape(obj, paranoid=True) | |
232 | elif util.safehasattr(obj, 'keys'): |
|
232 | elif util.safehasattr(obj, 'keys'): | |
233 | out = [] |
|
233 | out = ['%s: %s' % (json(k), json(v)) | |
234 |
for k, v in sorted(obj.iteritems()) |
|
234 | for k, v in sorted(obj.iteritems())] | |
235 | s = '%s: %s' % (json(k), json(v)) |
|
|||
236 | out.append(s) |
|
|||
237 | return '{' + ', '.join(out) + '}' |
|
235 | return '{' + ', '.join(out) + '}' | |
238 | elif util.safehasattr(obj, '__iter__'): |
|
236 | elif util.safehasattr(obj, '__iter__'): | |
239 | out = [] |
|
237 | out = [json(i) for i in obj] | |
240 | for i in obj: |
|
|||
241 | out.append(json(i)) |
|
|||
242 | return '[' + ', '.join(out) + ']' |
|
238 | return '[' + ', '.join(out) + ']' | |
243 | else: |
|
239 | else: | |
244 | raise TypeError('cannot encode type %s' % obj.__class__.__name__) |
|
240 | raise TypeError('cannot encode type %s' % obj.__class__.__name__) |
General Comments 0
You need to be logged in to leave comments.
Login now