I have a json file exported from phpmyadmin, it looks like this(utf-8 file):
[{"user_email": "bh549@sina.cn","followee_id": 1411833182,"create_date": "cdatetime datetime p1 (S\'\\x07\\xdb\\x06\\x13\\x16\\x08(\\r\\xd5\\xcc\' tRp2 ."}, {"user_email": "zaici4@sina.cn","followee_id": 1296426000,"create_date": "cdatetime datetime p1 (S\'\\x07\\xdb\\x07\\x14\\x179\\x16\\x02 \\x08\' tRp2 ."}, {"user_email": "yanaa357@sina.com","followee_id": 1848085255,"create_date": "cdatetime datetime p1 (S\'\\x07\\xdb\\x08\\x13\\x17\\x10\\x0f\\x05\\x1c\\x02\' tRp2 ."}]
each dict is a row in database, and third value in each row is a cpickled string.
then I use form to upload this file to a python script (with post method).
then parse this file in python script like this:
import cgi, os
import cgitb; cgitb.enable()
import json
#import simplejson as json
print "Content-type: text/html\n\n"
try:
import msvcrt
msvcrt.setmode (0, os.O_BINARY) # stdin = 0
msvcrt.setmode (1, os.O_BINARY) # stdout = 1
except ImportError:
pass
form = cgi.FieldStorage()
file_content = form['mysql_table'].value
file_content = json.loads(file_content)
then browser print a value error when execute json.loads:
<type 'exceptions.ValueError'>: Invalid control character at: line 1 column 83 (char 83)
the char 83 is a space in third value in first row.
How to fix this problem?
thanks mhawke anyway.but the first problem you said is not exist. There’s no \n because I copy that from print result, in my exported json file, it actually have \n
{"user_email": "bh549@sina.cn","followee_id": 1411833182,"create_date": "cdatetime
datetime
p1
(S\'\\x07\\xdb\\x06\\x13\\x16\\x08(\\r\\xd5\\xcc\'
tRp2
."}, {"user_email": "zaici4@sina.cn","followee_id": 1296426000,"create_date": "cdatetime
datetime
p1
(S\'\\x07\\xdb\\x07\\x14\\x179\\x16\\x02 \\x08\'
tRp2
."}
my be I misunderstand? second problem,It’s phpmyadmin escape the file when export,then how to fix the problem you said?
slouton: I’m write a python script to export table and transform the pickled data. It worked now, seems now way to handle json with pickled data.
Newlines are not valid in strings in JSON, and if phpMyAdmin is producing them then you should log a bug with the project.