任何人都可以帮我解决为什么这不起作用?当我通过浏览器提交URL时,我有一个返回以下JSON的URL:
{"Version":"1.0","Class":"ReportDefinition","Name":"My Report","Filter":{},"FilterList":{},"LineItems":"RA_LACE_VAL|~RA_LACE_RANK|~RA_LACE_TH10|~RA_LACE_TH25|~RA_LACE_TH50|~RA_LACE_TH75|~RA_LACE_TH90|~*|~*|~*<b>Overview Ratios|~EXRA_L_QR|~EXRA_L_USPA|~EXRA_L_CDPA|~EXRA_AQ_HRLPTL|~EXRA_AQ_LLATA|~EXAQR01ADJ|~EXAQR90ADJ|~EXRA_CA_ECAPA|~EXRA_CA_TECPTA|~EXRA_CA_TECPTAA|~EXRA_E_CROAE|~EXRA_E_ER|~*|~*|~*<b>SUPPORTING RATIOS:|~*|~*|~*<b>Earnings Ratios|~*|~EXFHP03ADJ|~EXFHP|~EXFHP02ADJ|~EXFHP05|~EXNISAEA|~EXFHP07|~EXYAAEATA|~EXIITOAA2|~EXIEATA|~EXFHP08|~*|~*<b>Capital Ratios|~*|~EX1FHCA07|~EX1RWATA|~EX1FHCA09|~EX1FHCA06|~EX1FHCA11|~EX1FHCA12|~EXCR01|~EX1RA_CA_TECPTA|~*|~*<b>Asset Quality Ratios|~*|~EXAQR03ADJ|~EXAQR051|~EXAQR04|~EXAQR19|~EXAQR17|~EXAQR20|~EXAQR18|~EXAQR30|~EXAQR36|~*|~*<b>Liquidity Ratios|~*|~EX1FHL04|~EXLLDR|~EXCDTA|~EXCDTDD|~EX2FHL02|~EXNCFDR250|~EXYSTNCFDR|~EXNCFDR|~*|~*<b>Loan Performance|~*|~*1-4 Family Loans|~EXLPQ2|~EXLPQ37|~*Home Equity Loans|~EXLPQ8|~EXLPQ38|~*1-4 Family Loans 2nd Mortgage|~EXLPQ5|~EXLPQ39|~*Multifamily Mortgage Loans|~EXLPQ11|~EXLPQ40|~*Commercial Real Estate Loans|~EXLPQ14|~EXLPQ41|~*Commercial & Industrial Loans|~EXLPQ17|~EXLPQ42|~*Agricultural Business Loans|~EXLPQ20|~EXLPQ43|~*Agricultural Real Estate Loans|~EXLPQ23|~EXLPQ44|~*Construction Loans|~EXLPQ29|~EXLPQ45|~*Credit Card Loans|~EXLPQ32|~EXLPQ46|~*Other Consumer Loans|~EXLPQ35|~EXLPQ47|~*|~*|~*<b>Securities Book Value|~*|~EXUSTBVPCT|~EXMUNISBVPCT|~EXTLMBSBVPCT|~EXABSTLBVPCT|~*|~*|~*<b>Deposit Growth|~*|~EXRCONPC2215|~EXRCONPC2385|~EXRCONPC2210|~EXRCONPC6810|~EXRCONPC0352|~EXRCONPC6648|~EXRCONPC2604|~EXRCONPCJ473|~EXRCONPCJ474|","Periods":"0_0_YTD~0_1_YTD~0_2_YTD~0_3_YTD","Ordering":"RA_LACE_VAL,0_0_YTD,asc","Layout":"[vertical]","Format":"[csv]","PageRows":"100000","PageCols":"100000","LimitPageRows":"N","LimitPageCols":"N","DescCols":"45","ColWidth":"14","FontSize":"1","SBSTotal":{},"GrandTotal":{},"MarketShare":{},"HHI":{},"SubtotalsOnly":{},"DynamicContent":"Y","Editable":"Y","PluginLayout":{},"IncludeCharts":"N","ChartDataType":{},"ChartGraphicType":{},"PageNumbering":"0","DoubleSpacing":"0","FitToPaper":"0","Header1Text":{},"HeaderJustify":{},"Footer1Text":{},"Footer2Text":{},"Footer3Text":{},"ChartDef":"0","UseTagNames":{},"PublishFilename":{}}
我已经在JSONLint中验证了JSON,它报告一切都很好。但是,当我从下面的ajax调用中调用相同的URL时,它会错误地将jqXHR textStatus和errorThrown错误地称为“parsererror”和“SyntaxError:Unexpected token”。
Per this stackoverflow post,我在服务器端使用了application / json标头,但是parseJSON仍然失败。我得到的最后一个警告是“数据不为空”......然后什么都没有。它甚至不会触发try / catch警报。这是ajax电话:
$.ajax({
url: strUrl,
type: "GET",
dataType: "json"
})
.fail(function( jqXHR, textStatus, errorThrown){
alert("error: "+textStatus+" : "+errorThrown);
})
.done(function(data) {
alert("success");
if( !data || data === ""){
alert("Server returned bad or empty data");
return false;
}else
alert("data not null");
var json;
try {
json = $.parseJSON(data);
} catch (ex) {
alert("There was an error translating the report XML. "+ex);
return false;
}
alert("json.Name: "+json.Name);
});
Chrome会报告错误:“未捕获的TypeError:无法读取属性'名称'为null”尽管我在发布“数据非空”后立即执行了try / catch。
答案 0 :(得分:0)
我遇到同样的问题。您只需删除dataType: 'json',
。