JAVA中的JavaScript类型数组 [英] JavaScript type arrays in JAVA
本文介绍了JAVA中的JavaScript类型数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在JAVA中显示以下JavaScript数组?
Is it possible to have JavaScript Array show below in JAVA?
var myArray = [ [‘2011-1-1’, 2],...]
我正在尝试将日期和值存储为一对在数组中。在JAVA中是否有一种替代方法可以做类似的事情?
I'm trying to store date and value as a pair in an array. Is there an alternative method in JAVA to do something similar?
推荐答案
猜猜你在谈论用Java保存/访问JSON格式。您可以使用像Gson这样的库来将响应解析为JsonArray,就像这样,
Guess you are talking about keeping/accessing JSON format in Java. You can achieve that using a library like Gson to parse the response into a JsonArray like so,
JsonArray yourArray = new JsonParser()
.parse("[[\"2012-14-03\", 2]]")
.getAsJsonArray();
// Access your array like so - yourArray.get(0).getAsString();
// yourArray.get(0).getAsInt() etc
Gson Library link - https://code.google.com/p/google-gson/
Gson Library link - https://code.google.com/p/google-gson/
这有帮助吗?
这篇关于JAVA中的JavaScript类型数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文