数组列表转换成JSON [英] convert Arraylist into json

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

问题描述

请帮我们怎么可以转换下面的ArrayList方法为JSON

 公开的ArrayList<串GT; helloName(字符串专利号){    ArrayList的<串GT;碧波=新的ArrayList<串GT;();    对于(INT行= 2;行< ROWSIZE;排++){
        PNO = driver.findElement(
                By.xpath(// * [@ ID ='身体'] /台/ TBODY / TR [+行+] / TD))
                .getText();
        bibo.add(PNO);
    }
    返回碧波;
}


解决方案

使用的 GSON 库这一点。下面是示例code

 的ArrayList<串GT;碧波=新的ArrayList<串GT;();
bibo.add(OBJ1);
bibo.add(obj2的);
bibo.add(obj3);
JSON字符串=新GSON()的toJSON(碧波)。

这个例子从GSON使用者使用指南它收集

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;
}

解决方案

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);

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

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

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