将Json数据解析为HTML而不使用Json数组名称
我有一个返回json数据列表的web服务。但是数据没有数组名。 数据的JSON格式如下所示:将Json数据解析为HTML而不使用Json数组名称,html,json,swing,parsing,model-view-controller,Html,Json,Swing,Parsing,Model View Controller,我有一个返回json数据列表的web服务。但是数据没有数组名。 数据的JSON格式如下所示: [{"itemno":1256,"offerPercent":10,"bulkDiscount":20,"regQtyBuyLimit":10,"offerQtyBuyLimit":5,"minReOrderLevel":2,"pkg":"5kg","addedOn":"2015-10-11","updatedOn":"2015-10-12","mrp":500,"regPrice":400,"minB
[{"itemno":1256,"offerPercent":10,"bulkDiscount":20,"regQtyBuyLimit":10,"offerQtyBuyLimit":5,"minReOrderLevel":2,"pkg":"5kg","addedOn":"2015-10-11","updatedOn":"2015-10-12","mrp":500,"regPrice":400,"minBulkQty":50}]
这是通过web服务调用从mysql获得的
我想把它解析成html表
我的问题是:如何在没有arrayname的情况下解析数据,或者如何定义数组的名称然后解析它?在成功调用时从服务器获取响应(如果使用简单的http表单提交请求或ajax调用),在responseData上调用$.parseJSON(responseData)
使用警报来验证您的数据。我已经自己解决了问题。 这次我会告诉你怎么做 以下是jsp文件的完整代码:-
<html>
<head>
<title>Lets See</title>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.getJSON('http://localhost:8080/OnlineStore/kmsg/grocery/item',
function (json) {
var tr;
for (var i = 0; i < json.length; i++) {
tr = $('<tr/>');
tr.append("<td>" + json[i].itemno + "</td>");
tr.append("<td>" + json[i].offerPercent + "</td>");
tr.append("<td>" + json[i].bulkDiscount + "</td>");
tr.append("<td>" + json[i].regQtyBuyLimit + "</td>");
tr.append("<td>" + json[i].offerQtyBuyLimit + "</td>");
tr.append("<td>" + json[i].minReorderLevel + "</td>");
tr.append("<td>" + json[i].pkg + "</td>");
tr.append("<td>" + json[i].addedOn + "</td>");
tr.append("<td>" + json[i].updatedOn + "</td>");
tr.append("<td>" + json[i].mrp + "</td>");
tr.append("<td>" + json[i].regPrice + "</td>");
tr.append("<td>" + json[i].minBulkqty + "</td>");
$('table').append(tr);
}
});
});
</script>
</head>
<body>
<table border="1">
<tr>
<th>ItemNo</th>
<th>OfferPercent</th>
<th>BulkDiscount</th>
<th>regQtyBuyLimit</th>
<th>offerQtyBuyLimit</th>
<th>minReorderLevel</th>
<th>pkg</th>
<th>addedOn</th>
<th>updatedOn</th>
<th>mrp</th>
<th>regPrice</th>
<th>minBulkqty</th>
</tr>
</table>
<button>Get Item</button>
</body>
</html>
让我们看看
$(文档).ready(函数(){
$.getJSON('http://localhost:8080/OnlineStore/kmsg/grocery/item',
函数(json){
var-tr;
for(var i=0;i
您指的是哪种数组名称?粘贴的JSON数据是非法的,请注意最后一个“,”。如果您使用var jsonData=JSON.parse('[{“itemno”:1256,“offerPercent”:10,“bulkDiscount”:20,“regQtyBuyLimit”:10}]')删除该字符串,
将您的JSON字符串解析为一种类型的对象
,您可以将其作为jsonData[0]
@kayes来处理,我已经编辑了JSON数据;“,”输入错误。@kayes array name是指开始时json数据上显示的名称。我不知道如何解析没有数组名称的json数据。。。。。。请在这方面帮助我…你有数据,然后使用这个函数