-4

我不知道如何解析 Finance.google.com 结果,即我得到了

[  
   {  
      "id":"787381",
      "t":"HDFC",
      "e":"NSE",
      "l":"1,424.00",
      "l_fix":"1424.00",
      "l_cur":"₹1,424.00",
      "s":"0",
      "ltt":"3:46PM GMT+5:30",
      "lt":"Sep 23, 3:46PM GMT+5:30",
      "lt_dts":"2016-09-23T15:46:54Z",
      "c":"+10.75",
      "c_fix":"10.75",
      "cp":"0.76",
      "cp_fix":"0.76",
      "ccol":"chg",
      "pcls_fix":"1413.25"
   }
]

当我使用 httpopenConnection 方法调用此端点时,我没有得到任何返回,因为我找不到 JSON 对象名称,我将在我的 android 应用程序中使用结果。

4

1 回答 1

-1

假设 js 是您选择的工具,并且由于您没有说明要对数组做什么,因此只需分配给一个名为 var 的变量obj,您就可以访问它 - 根据需要循环...

<!DOCTYPE HTML>
<html>
<body>

<h2>Manage a JSON Object in JavaScript</h2>

<p id="demo"></p>

<script>
var obj = [{"id":"787381","t":"HDFC","e":"NSE","l":"1,424.00","l_fix":"1424.00","l_cur":"&#8377;1,424.00","s":"0","ltt":"3:46PM GMT+5:30","lt":"Sep 23, 3:46PM GMT+5:30","lt_dts":"2016-09-23T15:46:54Z","c":"+10.75","c_fix":"10.75","cp":"0.76","cp_fix":"0.76","ccol":"chg","pcls_fix":"1413.25"}];

document.getElementById("demo").innerHTML =
obj[0].id + "<br>" +
obj[0].t + "<br>" +
obj[0].e + "<br>" +
obj[0].l + "<br>" +
obj[0].l_fix + "<br>" +
obj[0].l_cur + "<br>" +
obj[0].s + "<br>" +
obj[0].ltt + "<br>" +
obj[0].lt + "<br>" +
obj[0].lt_dts + "<br>" +
obj[0].c + "<br>" +
obj[0].c_fix + "<br>" +
obj[0].cp + "<br>" +
obj[0].cp_fix + "<br>" +
obj[0].ccol + "<br>" +
obj[0].pcls_fix + "<br>"; 


</script>
</body>
</html>

结果到浏览器的输出是:

Accessing a JSON Object in JavaScript

787381
HDFC
NSE
1,424.00
1424.00
₹1,424.00
0
3:46PM GMT+5:30
Sep 23, 3:46PM GMT+5:30
2016-09-23T15:46:54Z
+10.75
10.75
0.76
0.76
chg
1413.25
于 2016-09-24T08:49:27.393 回答