Python to javascript communication -


ok im using websockets let javascript talk python , works data need send has several parts array, (username,time,text) how send ? though encode each 1 in base64 or urlencode use character | encoding methods never use , split information. unfortunately cant find method both python , javascript can both do.

so question, there encoding method bath can or there different better way can send data because havent done before. (i have ajax requests , send data url encoded). im not sending miles of text, 100bytes @ time if that. thankyou !

edit

most comments point json,so, whats best convert use javascript because javascript stupidly cant convert string json,or other way round.

finished

well jaascript have native way convert javascript string, hidden form world. json.stringify(obj, [replacer], [space]) convert string , json.parse(string, [reviver]) convert back

use json module (or simplejson prior python 2.6).

you'd need remember 2 functions: json.dumps , json.loads.

>>> import json >>> json.dumps(['foo', {'bar': ('baz', none, 1.0, 2)}]) '["foo", {"bar": ["baz", null, 1.0, 2]}]' >>> json.loads('["foo", {"bar": ["baz", null, 1.0, 2]}]') [u'foo', {u'bar': [u'baz', none, 1.0, 2]}] 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -