简体   繁体   English

如何使用javascript或jquery读取典型的json数据

[英]how to read typical json data using javascript or jquery

hi all i am working on json data to show it on mobile apps how to read this type of json data 'limitvalue' 大家好,我正在研究json数据,以在移动应用程序上显示如何读取这种类型的json数据'limitvalue'

previously im sending all data to one object and reading but now it is not understandable how to read can some suggest me with some sample example. 以前我将所有数据发送到一个对象并进行读取,但是现在无法理解如何读取可以通过一些示例向我提出建议。

here is the json data that we want to use in that we need to show CoverageName and limitvalue. 这是我们要使用的json数据,我们需要显示CoverageName和limitvalue。

 [{"CoverageName":"Business Income"},{"CoverageName":"Employee Benefits Liability","Values":
{"Employee Benefits Liability Limit":{"limitvalue":"1000000"}}},{"CoverageName":"Extended Period
ofIndemnity"},{"CoverageName":"Limited Blanket Additional Insured"},{"CoverageName":"Non Owned 
Including Hired Automobile Coverage"},{"CoverageName":"Per Location Aggregate"},
{"CoverageName":"Tenant Legal Liability","Values":{"Tenant Legal Liability Limit"
:{"limitvalue":"100000"}}},{"CoverageName":"Employee Dishonesty","Values":{"Employee Dishonesty  
Limit":{"limitvalue":"5000"}}},{"CoverageName":"Supplemental Payments_Third Party Attorneys
 Fees"},{"CoverageName":"Employment Practices Liability","Values":{"EPLI Limit":  
{"limitvalue":"100000"},"EPLI Deductible":{"deductablevalue":"2500"}}},{"CoverageName":"Included
Coverage Package"},{"CoverageName":"Business Owners","Values":{"General Liability Aggregate
Limit":{"limitvalue":"2000000"},"General Liability Occurrence Limit":
{"limitvalue":"1000000"},"Total Building Limit":{"limitvalue":"0.0"},"Total Contents Limit":
{"limitvalue":"0.0"},"Property Deductible":{"deductablevalue":"100000"}}}]

Try jquery $.getJSON 试试jQuery $ .getJSON

  $.getJSON('your_json_file', function(data) {                            

          answers=data.CoverageName;//Objects of your file like CoverageName              

        alert(JSON.stringify(answers)); //object name to string           
        });     

first get this data in object then this code will help you 首先在对象中获取此数据,然后此代码将为您提供帮助

var jsonData = yourData;
var table = "table";
for(var i=0; i<jsonData.length; i++)
{
    table += "<tr><td>"+jsonData[i].CoverageName+"</td><td>"+jsonData[i].Values+"</td><tr>";
}
table += "</table>";

$('#yourDivID').append(table);

使用$ .parseJSON()

 Example  data_arr=$.parseJSON(data); //data json array

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM