最近我尝试使用AngularJS从API中获取一些字符串数据。除了以下字符串之外,我几乎从API获取每个字符串。以下所有字符串都返回“0”而不是显示来自API的字符串。
示例:我从以下Json API获取结果。
[{"ref_no":"105","ref_date":"2016\/12\/27","log_sheet":"65","branch":"SERVICEB","invoce_no":"8602","invoice_date":"9-11-2016","model_name":"HUAWEI L31","imei":"860906033283604","complaint":"DEAD","c_name":"KHATEEB","c_id":"11111111111","c_phone":"315784","c_cost":"0","battery":"Yes","battery_sno":"0","sim_card":"No","memory_card":"No","remark":"GOOD","esday":"10","branch_transfer":"transfered","branch_carrier":"RASHU","service_status":"Sent for Replacment Rquest","warranty_reason":"FIRMWARE NOT AVAILABLE(URGENT REPLACEMENT FROM OP MANAGER)","complete":"completed","s-return-driver":"","s-return-day":"","dealer-driver":"","pd-reason":"","m-status":"Approved","sbto":"19303","simei":"860906032309319","smodel":"Huawei GT3 4G","sdriver":"Unni","stransfer":"completed","staff_approve":"Approve","staff_drive":"ALI","staff_date":"27\/12\/16","print":"0","final":"0","m-reason":"please proceed","image-link":""}]
我使用以下代码使用AngularJS获取结果。
{{ x.m-reason }}
请让我知道为什么会这样。
答案 0 :(得分:1)
这是变量名称减号的问题,您可以更改{{ x['m-reason'] }}
它对我有用
答案 1 :(得分:0)
因为
Json
是一个带对象的数组 所以你可以从第0位获得对象。
尝试{{ x[0].m-reason }}
而不是{{ x.m-reason }}
。