Note that there are some explanatory texts on larger screens.

plurals
  1. POpython how to parse json file export from phpmyadmin
    primarykey
    data
    text
    <p>I have a json file exported from phpmyadmin, it looks like this(utf-8 file):</p> <pre><code>[{"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 ."}] </code></pre> <p>each dict is a row in database, and third value in each row is a cpickled string.</p> <p>then I use form to upload this file to a python script (with post method).</p> <p>then parse this file in python script like this:</p> <pre><code> 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) </code></pre> <p>then browser print a value error when execute json.loads:</p> <p><code>&lt;type 'exceptions.ValueError'&gt;: Invalid control character at: line 1 column 83 (char 83)</code> </p> <p>the char 83 is a space in third value in first row.</p> <p>How to fix this problem?</p> <p>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</p> <pre><code>{"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 ."} </code></pre> <p>my be I misunderstand? second problem,It's phpmyadmin escape the file when export,then how to fix the problem you said?</p> <p><strong>slouton:</strong> 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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload