I have this problem with my JSON file.
{"results" :[{
"name" : "name1",
"type" :[{
"id" : '2',
},{
"id" : '1',
},{
"id" : '4',
},{
"id" : '6',
}],
}],
"images" :[{
"url" : "url0",
},{
"url" : "url1",
},{
"url" : "url2",
},{
"url" : "url3",
},{
"url" : "url4",
}],
},{
"name" : "name2",
"type" :[{
{
"id" : '25',
},{
"id" : '123',
},{
"id" : '423',
},{
"id" : '346',
}],
"images" :[{
"url" : "url0",
},{
"url" : "url1",
},
{
"url" : "url2",
},
{
"url" : "url3",
},{
"url" : "url4",
}],
},
},{
"name" : "name3",
"type" : null,
"images" :null,
},.....
]}
the JSON object looks like this When i loop through the it kicks me out when it comes to the null
for(var i = 0; i < results.length; i++){
$('.results')append('<p class="liste">'+results[i].name+'</p><ul></ul>');
$('.liste').prepend('<img src="'+results[i].images[1].url+'"');
for(var j = 0; j < results[i].type.length; j++){
$('.results ul').append('<li>'+results[i].type[j].id+'</li>');
}
}
the result should look somewhat like this
<div class="results">
<img src="url1"><p>name1</p>
<ul>
<li>2</li>
<li>1</li>
<li>4</li>
<li>6</li>
</ul>
<img src="url1"><p>name2</p>
<ul>
</ul>
<img src="url1"><p>name3</p>
<ul>
<li>25</li>
<li>123</li>
<li>423</li>
<li>346</li>
</ul>
</div>
i tryed
if(results[i].images != null){
$('.liste').prepend('<img src="'+results[i].images[1].url+'">');
}else{
$('.liste').prepend('<img src="some default image" width="170" height="170">');
}
if(results[i].type != null){
for (var j = 0; j < results[i].type.length.length; j++) {
$('.album').append('<li>'+[i]+'-'+[j]+'-'+results[i].type.length[j].id+'</li>');
};
it gehts really messy the image comes for every [i] and the first [k] appears as it suppose to be as well as last [k] in in the pre. [i]
[i][j]
name1
[0][0]
[0][1]
[0][2]
[0][3]
[1][0]
name2
[1][0]
......
I hope some one can help me with that
EDIT I forgot every "type" is listed under each name.
results[i].type.length != nullthis seems strange. Shouldn't you checkresults[i].type != null?results[i].type != nullin the code