set the output stream encoding to "GB2312". /*** Write content to file CSV because CSV uses GB2312 encoding and needs to be processed separately*/@SuppressWarnings ("Resource") Public Static Booleancreatecsvfilewithcontent (String Parentpath, String fileName, String contentstr) {//Mark whether the file was generated successfully BooleanFlag =true; //stitching file Full pathString FullPath = P
Opencsv
Java read CSV Class library There are two main, opencsv and javacsv, the study found that javacsv last update is 2014-12-10, a long time does not maintain. Opencsv is an Apache project and is still being maintained, so decided to use Opencsv. CSV
CSV file, full name comma separated values, comma separated by d
JSON directly into the specified custom object, where list is fully parsed and map is not fully parsedMybeanwithperson Diybean = (Mybeanwithperson) Jsonobject.tobean (Jsonobject.fromobject (JSON), MyBeanWithPerson.class , Classmap);System.out.println (Diybean);System.out.println ("Do the list release");listfor (person O:list) {Person P = (person) o;System.out.println (P.getname ());}System.out.println ("Do
is not fully parsedMybeanwithperson Diybean = (Mybeanwithperson) Jsonobject.tobean (Jsonobject.fromobject (JSON), MyBeanWithPerson.class , Classmap);System.out.println (Diybean);System.out.println ("Do the list release");listfor (person O:list) {Person P = (person) o;System.out.println (P.getname ());}System.out.println ("Do the map release");To register the converter in the Registrar, you need to use the
:{name: ' test1 '},testtwo:{name: ' Test2 '}}"; Map Classmap=NewHashMap (); Classmap.put ("List", person.class); Classmap.put ("Map", map.class); //use the hint to parse the JSON directly into the specified custom object, where list is fully parsed and map is not fully parsedMybeanwithperson Diybean = (Mybeanwithperson) Jsonobject.tobean (Jsonobject.fromobject (JSON), MyBeanWithPerson.class, Classmap);
1. Json-lib is a Java class library that provides the ability to convert Java objects, including beans, maps, collections, Java Arrays and XML, to JSON, or reverse-transform.2. Json-lib Home: http://
);Classmap.put ("Map", Map.class);Use the hint to parse the JSON directly into the specified custom object, where list is fully parsed and map is not fully parsedMybeanwithperson Diybean = (Mybeanwithperson) Jsonobject.tobean (Jsonobject.fromobject (JSON), MyBeanWithPerson.class , Classmap);System.out.println (Diybean);System.out.println ("Do the list release");listfor (person O:list) {Person P = (person) o
The json string to the json object universal converter (implemented in java) is one hundred lines of code, which is very lightweight and compact. For general application scenarios, resource consumption is very low and the speed is fast enough, especially for Android application development.
CommonJSONParser can be used
Next, let's take a look at the following code:
Person. Java:
public class Person {private Date hire;public Date getHire() {return hire;}public void setHire(Date hire) {this.hire = hire;}public Person() {super();}public Person(Date hire) {super();this.hire = hire;}}
Test. Java:
public class Test {public static void main(String[] args) {test();}public static void test(){Person p=new Person(new Date());JSONO
not fully parsedMybeanwithperson Diybean = (Mybeanwithperson) Jsonobject.tobean (Jsonobject.fromobject (JSON), MyBeanWithPerson.class , Classmap);System.out.println (Diybean);System.out.println ("Do the list release");listfor (person O:list) {Person P = (person) o;System.out.println (P.getname ());}System.out.println ("Do the map release");Register the converter with the Registrar first and use the class i
the input stream into a BufferedReader object, and converts the Json to a Java object using the fromJson () method.
The first parameter of the fromJson () method of Gson supports parameters of the String, JsonElement, and Reader types and can be selected as needed. The second parameter of the fromJson () method supports Type and Class.
Type parameter. Class can be used when
Jackson is a set of data processing library tools for the Java platform, and Jackson's main function is to provide JSON parsing and generation, and Jackson also provides additional class libraries to support the processing of Avro, CBOR, CSV, Smile, XML, and YAML, It's very powerful and it's great to work with JSON dat
org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:368)at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:262)
In this case, you need to obtain support for json conversion packages.
VcD4KPHA + v8nS1NPJtuDW1re9yr3Ktc/expires + expires/1tDS/expires + CjxwPjxwcmUgY2xhc3M9 "brush: java;"> package com. waylau. rest; import org. codehaus. jackson. jaxrs. jac
String toString ()
{return
name + ': ' +age
}
}
The entity is very simple, two fields, of course, the field in the entity can also be a list or set type.
Gson Gson = new Gson ();
list
The above code focuses on the Gson object, which provides the Tojason () method to convert the object to a JSON string, with the Str object value of the above code:
[{"name":"name0","age":0},{"name":"name1","age":5},{"name":"name2","age":1
Java JSON processing class library Jackson
Jackson is a set of data processing class libraries provided for the Java platform. Jackson's main function is to provide JSON parsing and generation. In addition, Jackson also provides additional class libraries to support Avro, CBOR, CSV
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.