显示JSON数组中的HTML [英] Display JSON Array in HTML

查看:186
本文介绍了显示JSON数组中的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的localStorage JSON数组。我想找回这个数组,并显示值。
存储关键是 _myobject ,和值为

I have a JSON array in localstorage. I want to retrieve this array, and display the values. The storage key is _myobject, and the value is

[{"64508":"12:12:2"},{"5292":"12:17:34"}]

我要的是要知道如何使用JavaScript / jQuery的显示/按以下格式打印值:

What I want is to know how I can use JavaScript/jQuery to display/print the values in the following format:

Number: 64508 - Time:  12:12:2
Number: 5292 - Time: 12:17:34

可能有人请告诉我,我怎么能做到这一点?

Could somebody please direct me on how I could do this?

推荐答案

您可以使用的 Array.map 从您的数组转换成字符串。尝试是这样的:

You can use an Array.map to convert from your array into the string. Try something like this:

var obj = JSON.parse(localStorage.getItem("_myobject"));
obj.map(function(item) { 
     // (really just the first key)
     for (var key in item) 
         return "Number: " + key + " - Time: " + item[key]; 
}).join(" ");

(小提琴)

这篇关于显示JSON数组中的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆