JSP arraylist到javascript变量 [英] JSP arraylist to javascript variable

查看:94
本文介绍了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>

推荐答案

.ajax({
url:data。 json,
dataType:json,
成功:函数(数据){
var f = data.c1;
alert(f);
alert( test);
}


});

< / script>
.ajax({ url: "data.json", dataType: "json", success: function(data){ var f = data.c1; alert(f); alert("test"); } }); </script>


因为您的对象包含属性C1,而不是c1。 JavaScript区分大小写,您需要注意这一点。使用此,

Because your object contains a property C1, not c1. JavaScript is case-sensitive, and you need to take care of that. Use this,
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变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆