I´m populating webpage with sharepoint so I do a json to get data with ajax like these:
我´填充网页与sharepoint所以我做一个json数据与ajax这样的:
function completeFleet(data, target, eng) {
var items = data.d.results;
console.log(items);
var prefix = "<div class='row'>";
var sufix = "</div>";
var menu = "<div class='col-md-4'>";
var cat = "";
var spec = "";
var counter = 0;
var obj = null;
for (item in items) {
spec = "";
if (counter == 1) {
menu += "</div><div class='col-md-4'>";
counter = 0;
}
if (eng) {
obj = JSON.parse(items[item].Specifications);
for (var key in obj) {
spec += "<div class='row'><div class='col-md-12 ftBottomSeparator'><span class=' t10'>" + key + "</span> <span class='t06' style='float:right;'>" + obj[key] + "</span></div></div>";
}
menu += "<div class='row ftContainerOut'><div class='col-md-12 ftContainer'><div class='row ftHeader'><div class='col-xs-9 t09'>" + items[item].Title + "</div><div class='col-xs-3 text-right'></div></div><div class='row'><div class='col-md-6' style='padding-top:10px'><img src='" + items[item].Imagen.Url + "' class='img-responsive img-center' style='border:0px solid blue; max-width:150px;max-height:120px;' /></div><div class='col-md-6'>" + spec + "</div></div></div></div>";
} else {
obj = JSON.parse(items[item].Especificaciones);
for (var key in obj) {
spec += "<div class='row'><div class='col-md-12 ftBottomSeparator'><span class=' t10'>" + key + "</span> <span class='t06' style='float:right;'>" + obj[key] + "</span></div></div>";
}
menu += "<div class='row ftContainerOut'><div class='col-md-12 ftContainer'><div class='row ftHeader'><div class='col-xs-9 t09'>" + items[item].Title + "</div><div class='col-xs-3 text-right'></div></div><div class='row'><div class='col-md-6' style='padding-top:10px'><img src='" + items[item].Imagen.Url + "' class='img-responsive img-center' style='border:0px solid blue; max-width:150px;max-height:120px;' /></div><div class='col-md-6'>" + spec + "</div></div></div></div>";
}
counter++;
}
$(target).html("<div class='panel-body'><div class='container-fluid'>" + prefix + menu + sufix + "</div></div>");
}
I have 5 objects different, but one of these don´t show data, my webpage is in english and spanish, in english it charge all data, but in spanish one of these doesn´t works and I get error at position 36, and position 36 is the item don´t show. Any idea what is wrong here? Regards
我有5个对象不同,但´其中一个不显示数据,我的网页是在英语和西班牙语,英语它所有数据,但在西班牙一个´t 36作品和我得到错误的位置,和位置36´的项目不显示。你知道这里有什么问题吗?问候
这些一个作品
and this no works
这没有工作
---------Update------------
- - - - - - - - - - - update - - - - - - - - - - - -
If I comment this line:
如果我评论这句话:
//obj = JSON.parse(items[item].Especificaciones);
and put
并将
if(items[item].Especificaciones){
JSON.parse(items[item].Especificaciones);
}
it now runs with image, but now I don´t have my "Especificaciones" lists
现在运行与形象,但现在我也´t“Especificaciones”列表
Now when I use
现在,当我用
var stringifyObj = JSON.stringify(items[item].Especificaciones);
var obj = JSON.parse(stringifyObj);
I get something like these:
我得到了这样的东西:
2 个解决方案
#1
1
make sure value is not null for the corresponding key inside JSON.parse. For example-
确保JSON.parse内对应的键的值不是null。例如,
JSON.parse(items[item].Specifications)
make sure items have value in item index and items[item] has the property Specifications.
确保项目在项目索引中具有值,项目[项目]具有属性规范。
you can check if items[item].Specifications is not null before JSON.parse.
你可以检查项目[项目]。在JSON.parse之前,规范不是空的。
if(items[item].Specifications){
JSON.parse(items[item].Specifications)
}
Update
更新
JSON.parse() is used to convert a string containing JSON notation into a Javascript object. To be valid JSON, strings must be in double quotes.
parse()用于将包含JSON符号的字符串转换为Javascript对象。要成为有效的JSON,字符串必须使用双引号。
Try stringify the object and then parse again.
尝试对对象进行stringify,然后再次解析。
var stringifyObj = JSON.stringify(items[item].Especificaciones);
var obj = JSON.parse(stringifyObj);
The reason for the error is that JSON.parse() expects a String value and items[item].Especificaciones is an Array
出现错误的原因是JSON.parse()需要一个字符串值和items[item]。Especificaciones是一个数组
#2
1
"Eslora":100 pies"
“Eslora”:100年派”
You should probably opening the quotes when you start writing a string value
您应该在开始编写字符串值时打开引号。
#1
1
make sure value is not null for the corresponding key inside JSON.parse. For example-
确保JSON.parse内对应的键的值不是null。例如,
JSON.parse(items[item].Specifications)
make sure items have value in item index and items[item] has the property Specifications.
确保项目在项目索引中具有值,项目[项目]具有属性规范。
you can check if items[item].Specifications is not null before JSON.parse.
你可以检查项目[项目]。在JSON.parse之前,规范不是空的。
if(items[item].Specifications){
JSON.parse(items[item].Specifications)
}
Update
更新
JSON.parse() is used to convert a string containing JSON notation into a Javascript object. To be valid JSON, strings must be in double quotes.
parse()用于将包含JSON符号的字符串转换为Javascript对象。要成为有效的JSON,字符串必须使用双引号。
Try stringify the object and then parse again.
尝试对对象进行stringify,然后再次解析。
var stringifyObj = JSON.stringify(items[item].Especificaciones);
var obj = JSON.parse(stringifyObj);
The reason for the error is that JSON.parse() expects a String value and items[item].Especificaciones is an Array
出现错误的原因是JSON.parse()需要一个字符串值和items[item]。Especificaciones是一个数组
#2
1
"Eslora":100 pies"
“Eslora”:100年派”
You should probably opening the quotes when you start writing a string value
您应该在开始编写字符串值时打开引号。