Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You shouldn't have to do it that complicated, and the Json in the top of your post is invalid. Maybe this is something that you want?</p> <pre><code>{ "Altimetry": [ { "legenrowname": "0m - 250m ", "fillcolor": "005500", "bordercolor": "" }, { "legenrowname": "250m - 1000m ", "fillcolor": "ffff7f", "bordercolor": "" }, { "legenrowname": "1000m - 5000m ", "fillcolor": "B47811", "bordercolor": "" }, { "legenrowname": "+ 5000m ", "fillcolor": "482400", "bordercolor": "" } ] } </code></pre> <p>Check your incoming JSON with <a href="http://jsonlint.com/" rel="nofollow">http://jsonlint.com/</a> if it's valid. Did you generate the JSON yourself? do a console.log(jsonString) and paste it to jsonlint.</p> <p>With a valid piece of JSON, you can use <code>JSON.parse(jsonString)</code>- do not add any extra brackets like <code>var dataL = ${dataJsonLegends};</code> </p> <p>Right now it looks like you're looping over every single character in your response string</p> <p>EDIT</p> <p>Your updated JSON is valid, this is how I would process it:</p> <pre><code>var json = [{"uid":1,"legendname":"Altimetry","legend_description":null,"rows":[{"uid":2,"legendrowname":"250m - 1000m","fillcolor":"ffff7f","bordercolor":null,"rast_value":null,"fillcolorrgb":null,"bordercolorrgb":null,"legendrow_description":null,"legend":null},{"uid":4,"legendrowname":"+ 5000m","fillcolor":"482400","bordercolor":null,"rast_value":null,"fillcolorrgb":null,"bordercolorrgb":null,"legendrow_description":null,"legend":null},{"uid":1,"legendrowname":"0m - 250m","fillcolor":"005500","bordercolor":null,"rast_value":null,"fillcolorrgb":null,"bordercolorrgb":null,"legendrow_description":null,"legend":null},{"uid":3,"legendrowname":"1000m - 5000m","fillcolor":"B47811","bordercolor":null,"rast_value":null,"fillcolorrgb":null,"bordercolorrgb":null,"legendrow_description":null,"legend":null}],"layer":{"id":1,"description":"Altimetry","geoserver":"/geoserver/Sopcawind/wms","name":"Sopcawind:srtm","transparent":true,"format":"image/png","viewparams":"","isbaselayer":false,"opacity":0.5,"color":"#2b383b","visibility":false,"groupid":1,"infocontrol":true,"geometry":"","featuretype":"","srs":"","extradata":"","legends":null,"project":null}}]; for(i = 0; i&lt;json.length; i++) { console.log("new array item"); console.log(json[i].uid); console.log(json[i].legendname); console.log(json[i].legenddescription); for(j = 0; j&lt;json[i].rows.length; j++) { console.log("new row"); console.log('\t' + json[i].rows[j].uid); console.log('\t' + json[i].rows[j].legendrowname); console.log('\t' + json[i].rows[j].fillcolor); console.log('\t' + json[i].rows[j].bordercolor); // and so on... } } </code></pre> <p>EDIT 2</p> <p>Why not just create as javascript objects then, if you need the json after just stringify</p> <p>something like this (maybe not exact):</p> <pre><code>var objArr = new []; $.each(dataL, function(i, item){ var leg = new Object(); leg.uid = item.uid; leg.legendname = item.legendname; leg.rows = []; $.each(dataR, function(j, item2){ var rw = new Object(); rw.uid = item2.uid; rw.legendrowname = item2.legendrowname // and so on leg.rows.push(rw); }); objArr.push(leg); }); alert(JSON.stringify(objArr)); </code></pre>
    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. 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