[英]fetch json value with no key using jquery
i am having trouble fetch JSON using jQuery, if possible someone tell me what mistake i made because my code is not working 我在使用jQuery提取JSON时遇到问题,如果可能,有人告诉我我的错误是因为我的代码无法正常工作
data.json file contain data.json文件包含
{ "value1", "value2", "value3", "value4" }
and here is my jquery code 这是我的jQuery代码
$.getJSON( "data.json", function( data ) { $.each( data, function( val ) { alert(val); }); });
use []
instead of {}
in the json file as suggested in the comment as your current json is not a valid JSON. 按照注释中的建议在json文件中使用[]
代替{}
,因为您当前的json不是有效的JSON。 Then you can access the file data this way. 然后,您可以通过这种方式访问文件数据。
$.each(data, function(i,val) {
alert(val);
});
Notice, that your current code only access the index of the value but not the actual value. 注意,您当前的代码仅访问值的索引,而不访问实际值。 Place the both parameter i
and val
to get both index and value from the file. 同时放置参数i
和val
以从文件中获取索引和值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.