本文介绍了JSP arraylist到javascript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含...的data.json文件。
I am having a data.json file containing...
{"C13":0,"C24":0,"C35":0,"C46":0,"C57":0,"C12":105.23,"C23":0.18,"C34":124.3,"C45":132.49,"C56":145.39,"C14":60.46,"C25":0.18,"C36":84.3,"C47":93.24,"C58":97.7,"C1":146.78,"C2":0,"C3":94.15,"TS":"16:55:24"}
现在我必须在javascript中获取值...
提醒返回未定义..
需要帮助...
我是什么尝试过:
now I have to get the values in javascript...
alert returning "undefined"..
need help...
What I have tried:
<script src="js/jquery.min.js"></script>
<script type="text/javascript">
$.ajax({
url: "data.json",
dataType: "json",
success: function(data){
var f = data.c1;
alert(f);
alert("test");
}
});
</script>
推荐答案
var f = data.C1;
自提醒显示未定义,它显然意味着属性未定义,对象不是。如果数据未定义,则表示无法读取未定义的属性'c1'。但是,如果数据属于另一种类型,那么它会说出与第二个错误类似的内容。
Since your alert is showing undefined, it clearly means that the property is undefined, the object is not. If the data was undefined, it would have said "cannot read property 'c1' of undefined". If, however, the data was of another type, then it would have said something or similar to the second error.
这篇关于JSP arraylist到javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!