如果我的JSON字符串太大,它不会在我的javascript中验证。例如,如果服务器返回15个结果,它将会失败。 如果它只返回10,它将被验证。JSON over 7k将无法验证
这里是失败的JSON
{
"results":[
{
"mls":"20480",
"address":"518 WALNUT",
"dbcity":"ALTA",
"dbstate":"IL",
"zip":"61414",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"Great 1880 farm house with many updates including half circle screened back deck wants TLC. Large above ground pool",
"srcDB":"spi",
"beds":"4",
"baths":"1"
},
{
"mls":"6145",
"address":"1074 Spoden",
"dbcity":"GALE",
"dbstate":"Il",
"zip":"61401",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"This 3BR 2BA custom Ranch is located in Lawndale Acres. Features include",
"srcDB":"spi",
"beds":"3",
"baths":"2"
},
{
"mls":"6146",
"address":"529 SCOTCH ELM",
"dbcity":"GALE",
"dbstate":"IL",
"zip":"61401",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"Enticing 3BD 2BA Tri-level home situated on a large",
"srcDB":"spi",
"beds":"3",
"baths":"1"
},
{
"mls":"157186",
"address":"277 WALNUT AVE",
"dbcity":"GALE",
"dbstate":"IL",
"zip":"61401",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"2 bedroom 1 bath bungalow. Spacious kitchen with pantry",
"srcDB":"spi",
"beds":"2",
"baths":"1"
},
{
"mls":"6148",
"address":"404 Second",
"dbcity":"MONM",
"dbstate":"Il",
"zip":"61462",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"This 1895 Queen Anne Victorian near Monmouth College has an open staircase",
"srcDB":"spi",
"beds":"4",
"baths":"2"
},
{
"mls":"175111",
"address":"483 KINGS CANYON",
"dbcity":"GALE",
"dbstate":"IL",
"zip":"61201",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"Coveted 3 BR",
"srcDB":"spi",
"beds":"3",
"baths":"2"
},
{
"mls":"20491",
"address":"306 Austin",
"dbcity":"ABIN",
"dbstate":"IL",
"zip":"61410",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"Charming 2BR home with many interior improvements having recently been done. You have to see this one! Attached garage. TMI Home Warranty.",
"srcDB":"spi",
"beds":"2",
"baths":"1"
},
{
"mls":"20492",
"address":"614 DEPOT",
"dbcity":"ALTA",
"dbstate":"IL",
"zip":"61414",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"Nice 3 bedroom ranch on crawl",
"srcDB":"spi",
"beds":"3",
"baths":"1"
},
{
"mls":"160268",
"address":"947 Frank St.",
"dbcity":"GALE",
"dbstate":"IL",
"zip":"61401",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"This cute and charming 2 bedroom home is immediately available. Move right in or put your special touches to it and make it your own. Some great features to notice are the new roof (2016)",
"srcDB":"spi",
"beds":"2",
"baths":"1"
},
{
"mls":"6157",
"address":"2555 Costa",
"dbcity":"GALE",
"dbstate":"IL",
"zip":"61401",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"Entertain handsomely in this exhilarating 5BR 4BA 2-story home situated on 2.93 acres. You can find many desirable features including: ADT home security system",
"srcDB":"spi",
"beds":"5",
"baths":"2"
},
{
"mls":"20493",
"address":"432 HOLMES",
"dbcity":"ONEI",
"dbstate":"IL",
"zip":"61467",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"Nice ranch home with many updates! New carpet",
"srcDB":"spi",
"beds":"3",
"baths":"1"
},
{
"mls":"6158",
"address":"168 Pleasant",
"dbcity":"GALE",
"dbstate":"Il",
"zip":"61401",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"Quaint 3BR brick bungalow situated on a nice large lot. Enjoy a peaceful night in the enclosed front porch overlooking the quiet street. Inviting features include natural woodwork & hardwood flooring",
"srcDB":"spi",
"beds":"3",
"baths":"1"
},
{
"mls":"20494",
"address":"115 F",
"dbcity":"ALPH",
"dbstate":"IL",
"zip":"61413",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"2BR home on large corner lot w/ newer roof and covered deck.",
"srcDB":"spi",
"beds":"2",
"baths":"1"
},
{
"mls":"20495",
"address":"263 FULTON",
"dbcity":"GALE",
"dbstate":"IL",
"zip":"61401",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"Spacious 4BR 2BA with formal LR & DR",
"srcDB":"spi",
"beds":"4",
"baths":"2"
},
{
"mls":"20496",
"address":"39 Knox Rd 2150N",
"dbcity":"GALE",
"dbstate":"Il",
"zip":"61401",
"openHouse1":"",
"openHouse2":"",
"openHouseAvail":"",
"listPrice":"0",
"remarks":"Beautiful fenced-in 5 acres to enjoy family outings and create memories! Small pond and 3-stall shed for horses or other pets. Property is being sold ''As Is.'' Please see supplement for additional information.",
"srcDB":"spi",
"beds":"2",
"baths":"1"
}
],
"counter":15,
"error":"0"
}
当我检查它在https://jsonformatter.curiousconcept.com/
我以前用过的更大的JSON字符串这验证。发生什么事?
我的JavaScript看起来像:
$.ajax({
url: "../cgi/search.exe",
dataType: "json",
type: "POST",
data: dataString,
error: ajaxError,
success: function(json){
if(json.error !== "0"){
alertify.alert("ERROR "+json.error);
return;
}
和解析Ajax错误的功能是
// generic ajax error handler
function ajaxError(request, type, errorThrown) {
var message = "There was an error with the AJAX request.\n";
switch (type) {
case 'timeout':
message += "The request timed out.";
break;
case 'notmodified':
message += "The request was not modified but was not retrieved from the cache.";
break;
case 'parsererror':
message += "XML/Json format is bad.";
break;
default:
try{
message += "HTTP Error (" + request.status + " " + request.statusText + ").";
}catch(e){
return;
}
}
alertify.alert(message);
}
我能解析JSON就好了。我猜想在后来的其中一个记录中有一些隐藏的字符,它在创建问题时迷失了方向。 –
您是否尝试对文件中的字符串进行硬编码并解析它?你在尝试使用哪些浏览器?什么是你得到的确切的错误信息(因为我也无法重现)?请访问帮助中心,阅读如何在此提问,包括制作MCVE。 –
似乎解析就好[这里](https://jsfiddle.net/mirohristov/ds7dewvo/)。什么是所有的反对票?现在不能问一个问题。就像你必须已经完美。 Geez – Miro