Note that there are some explanatory texts on larger screens.

plurals
  1. POJson list to javascript object to build a form
    primarykey
    data
    text
    <p>i'm not sure about how JSON's lists work when parsed as javascript objects. But however i'm niether used to javascript, so my question and the proposed solution could contain stupid mistakes. I have a JSON file, and i have to build a form from it, so i'm parsing it with jQuery .parseJSON to obtain a javascript object. The json file is the following:</p> <pre><code>{"Form": [{"Name":"Conan", "Description":"Adventure", "Value":"Children Movie"}, {"Name":"Sandocan", "Description":"Adventure", "Value":"Children Movie"}, {"Name":"Terminator", "Description":"Sci-Fi", "Value":"Action Movie"}, {"Name":"Iron Man", "Description":"Adventure", "Value":"Children Movie"}]} </code></pre> <p>It should be right from the syntax point of view.</p> <p>The code tha processes it is in a web page, the JSON code is printed in the page by a template tag: {{line}}. I tried assigning it to a variable but i'm still not sure if the code really processes it. However the code of the page is below:</p> <pre><code>&lt;html&gt;&lt;script src="../jquery.js"&gt; &lt;/script&gt; &lt;body&gt;&lt;p&gt; Data previously inserted: {{line}}&lt;/p&gt; &lt;form action="/myform/" method="post"&gt;Choose the movie you prefer:&lt;br /&gt; &lt;script language=javascript&gt; var lin={{line}} var obj=jQuery.parseJSON(lin); function str_to_obj(o){ document.write("Hello world"); for(item in o.Form) { document.write(item.Name); }; } str_to_obj(obj); &lt;/script&gt; &lt;input type="radio" name="title"&gt;&lt;br /&gt; &lt;input type="text" name="description"&gt;&lt;br /&gt; &lt;input type="submit" value="Submit"&gt; &lt;/form&gt;&lt;/body&gt;&lt;/html&gt; </code></pre> <p>Firebug reports: </p> <pre><code>SyntaxError: invalid property id var obj=jQuery.parseJSON({&amp;quot;Form&amp;quot;: [{&amp;quot;Name&amp;quot;:&amp;quot;Conan&amp;quot; </code></pre> <p>I'm doing something silly, i'm sure, but i have to make it work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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