Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>JavaScript part - encoding</h2> <p>In Javascript you do:</p> <pre class="lang-js prettyprint-override"><code>var arr = ["a","b",,,"e"]; var json_string = JSON.stringify(arr); </code></pre> <p>then you somehow pass <code>json_string</code> (now equal to "<code>["a","b",null,null,"e"]</code>" string) from JavaScript to Python.</p> <h2>Python part - decoding</h2> <p>Then, on Python side do:</p> <pre class="lang-py prettyprint-override"><code>json_string = '["a","b",null,null,"e"]' # passed from JavaScript try: import simplejson as json except (ImportError,): import json result = json.loads(json_string) </code></pre> <p>As a result you get <code>[u'a', u'b', None, None, u'e']</code> in Python.</p> <h2>More links</h2> <p>See below:</p> <ul> <li><a href="http://jsfiddle.net/Gtehr/">demo of JavaScript part</a>,</li> <li><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/JSON/stringify">Documentation on JSON.stringify() at Mozilla Developer Network</a>,</li> <li><a href="http://ideone.com/oqnQZ">demo of Python part</a>,</li> </ul> <h2>Dependencies</h2> <p>The above solutions require:</p> <ul> <li><code>JSON.stringify()</code> in JavaScript, which is in all mobile browsers, Chrome, Firefox, Opera, Safari and in IE since version 8.0 (more detailed list of compatible browsers is <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Browser_compatibility">here</a>),</li> <li><code>json</code> Python library (the above code will use <code>simplejson</code> optionally, if available, but is not required), which comes in standard library,</li> </ul> <p>So, in short <strong>there are no external dependencies</strong>.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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