Javascript错误:解析云代码时出现意外字符串
我试图从httpresponse获取信息,解析de JSON并创建一个新字典,其中包含一系列字典,如:Javascript错误:解析云代码时出现意外字符串,javascript,json,parse-platform,Javascript,Json,Parse Platform,我试图从httpresponse获取信息,解析de JSON并创建一个新字典,其中包含一系列字典,如: "data" : {"infracciones": [ { "folio": "03041487403", "fecha": "2014-03-16", "situacion": "Pagada", "motivo": "POR NO RESPETAR LOS LIMI
"data" : {"infracciones": [
{
"folio": "03041487403",
"fecha": "2014-03-16",
"situacion": "Pagada",
"motivo": "POR NO RESPETAR LOS LIMITES DE VELOCIDAD",
},
{
"folio": "0334357403",
"fecha": "2015-04-11",
"situacion": "Pagada",
"motivo": "POR NO RESPETAR LOS LIMITES DE VELOCIDAD",
}],
"tenencia":[ ...]
}
但我得到了错误:“main.js:35中的意外字符串”但我不知道发生了什么,谢谢你的帮助,下面是代码:
Parse.Cloud.httpRequest({
url: url1 ,
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
}).then(function(httpResponse) {
var json = JSON.parse(httpResponse.data);
var datos = json.infracciones;
var infracciones = [];
var data = {};
var i = 0;
for(i = 0; i < datos.length ; i++){
infracciones[i].["folio"] = datos.folio ; // THIS IS LINE 35
infracciones[i].["fecha"] = datos.fecha ;
infracciones[i].["situacion"] = datos.situacion ;
infracciones[i].["motivo"] = datos.motivo ;
}
data.push({
key : "infracciones",
value : infracciones
});
response.success(data);
console.log(httpResponse.text);
}, function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
});
Parse.Cloud.httpRequest({
url:url1,
标题:{
“内容类型”:“应用程序/json;字符集=utf-8”
}
}).then(函数(httpResponse){
var json=json.parse(httpResponse.data);
var datos=json.infracciones;
var infracciones=[];
变量数据={};
var i=0;
对于(i=0;i
试试这种方法
var infracciones = [];
var data = [];
var i = 0;
for(i = 0; i < datos.length ; i++){
infracciones[i] = {};
infracciones[i].folio = datos.folio ;
infracciones[i].fecha = datos.fecha ;
infracciones[i].situacion = datos.situacion ;
infracciones[i].motivo = datos.motivo ;
}
data.push({
key : "infracciones",
value : infracciones
});
var-infracciones=[];
var数据=[];
var i=0;
对于(i=0;i
将此添加到该行之前infracciones[i]={}编码>并更改infracciones[i].[对开本]
=>infracciones[i].[对开本].
删除的点运算符或删除。或该行中的[“和”]以及下一行中的3well@Tushar谢谢,但现在我得到了这个错误=“Uncaught SyntaxError:Unexpected token u in\u003c已知文件\u003e:1”,你知道可能是什么吗?@JaromandaX谢谢,现在我得到了这个错误=“Uncaught SyntaxError:Unexpected token u in\u003c已知文件\u003e:1”,你知道会是什么吗?你可能把编辑搞砸了