2015-04-07 48 views
-5
{ 
    u'stores': [ 
     { 
      u'name': u'Mega', 
      u'img': u'http: //www.modiin.azrieli.com/pictures/logo_mega-01.jpg' 
     }, 
     { 
      u'name': u'Shufersal', 
      u'img': u'http: //msc.wcdn.co.il/archive/136894-5.jpg' 
     } 
    ], 
    u'success': True 
} 

JSONLint.com这样说:虽然我似乎这个JSON有什么问题?

Parse error on line 1: 
{ u'stores': [  
-----^ 
Expecting 'STRING', '}' 

无法理解什么是错的。这个JSON是在JavaScript中使用JSON.stringify生成的。

编辑:感谢您的帮助,它是一个字符串关闭python而不是JSON。

+3

每串之前的“u”是什么? – karkael

+0

这不是JSON,它是一个'repr'编码的Python'字典' – Kos

+1

“*这个JSON是在JavaScript中使用JSON.stringify生成的*。” - 你能显示创建它的代码吗?在任何情况下,JavaScript的'JSON.stringify'都不会产生像这样的输出。这看起来更可能是由Python产生的,从'u'前缀的字符串来判断。 – apsillers

回答

4

JSON字符串由""而不是u''定界。

您的数据以Python文字语法表达。

[ quentin ][ [email protected] ] % python 
Python 2.7.6 (default, Sep 9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> foo = { 
...  u'stores': [ 
...   { 
...    u'name': u'Mega', 
...    u'img': u'http: //www.modiin.azrieli.com/pictures/logo_mega-01.jpg' 
...   }, 
...   { 
...    u'name': u'Shufersal', 
...    u'img': u'http: //msc.wcdn.co.il/archive/136894-5.jpg' 
...   } 
...  ], 
...  u'success': True 
... } 
>>> 
>>> foo 
{u'stores': [{u'name': u'Mega', u'img': u'http: //www.modiin.azrieli.com/pictures/logo_mega-01.jpg'}, {u'name': u'Shufersal', u'img': u'http: //msc.wcdn.co.il/archive/136894-5.jpg'}], u'success': True}