未捕获的类型错误:无法读取属性'ht_4year_risk_opt'为null

Uncaught TypeError: Cannot read property 'ht_4year_risk_opt' of null

本文关键字:ht risk null opt 4year 属性 类型 错误 读取      更新时间:2023-09-26

我正试图调用servlet,它将返回json数据,但在解析时我收到了这个错误。

var jsondata = jQuery.parseJSON(data);
var ht_4year_risk_opt = jsondata.ht_4year_risk_opt;

这个命令会告诉您jQuery.parseJSON(data)导致null。两个可能的原因:

  1. 实际上是字符串"null"jQuery.parseJSON("null")返回null

  2. (更有可能)datanull,然后parseJSON将其转换为字符串"null",然后进行解析。(jQuery.parseJSON(null)返回null

所以你会想知道为什么datanull"null"

相关文章: