将 Arraylist 转换为 json [英] convert Arraylist into json

查看:288
本文介绍了将 Arraylist 转换为 json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我们如何将下面的 Arraylist 方法转换为 Json

please help how could we convert the below Arraylist method into Json

public ArrayList<String> helloName(String patentno)  {

    ArrayList<String> bibo = new ArrayList<String>();

    for (int row = 2; row < rowsize; row++) {
        pno = driver.findElement(
                By.xpath("//*[@id='body']/table/tbody/tr[" + row + "]/td"))
                .getText();
        bibo.add(pno);
    }
    return bibo;
}

推荐答案

使用 GSON 库.这是示例代码

Use GSON library for that. Here is the sample code

ArrayList<String> bibo = new ArrayList<String>();
bibo.add("obj1");
bibo.add("obj2");
bibo.add("obj3");
String json = new Gson().toJson(bibo);

以及来自 Gson 用户的 这个示例收藏使用指南

And this example from Gson User Guide to use it on collection

这篇关于将 Arraylist 转换为 json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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