You are still worrying about the variable in the document, the json with complicated structure~

Wrong one type, then various crashes

Wrong to write a variable name can not be resolved

The code tool is coming~

Automatically generate javabean class, just one key~

This series of code tools is dedicated to this, doing these boring tasks for you, giving you more time to study new poses.

Instructions

First import the code tool into Eclipse, the project is Java Project, pay attention to not Android Project

1. Copy the json string data to the jsonString.txt file in the project.

(json data can be obtained from the json data example in the document, or by running the interface call code to print the json string first)

2. Run the JsonUTIls class in the code tool, where the main function will run the json parsing main method.

3. Open the JsonBean.java file, refresh, copy and use the automatically generated javabean class directly.

supplement

If you need public modification variables, you can use ctrl+F to replace them all.

If you need to generate getter and setter methods, you can right click on Source->Generate Getter and Setter to set

The tool code is open source and can be modified as needed.

Ok, the tool ends here, and the code principle is introduced later.

principle

Project is a Java Project

Use the Gson tool to parse the string tree structure, and then use the File IO stream to write the bean structure to the file according to the requirements.

Visible source code in the project, conscience annotation, almost 2 lines of code 1 line comment

Here also posted the code of the core class JsonUTIls

Package uTIls;

Import java.io.File;

Import java.uTIl.ArrayList;

Import java.util.Iterator;

Import java.util.List;

Import java.util.Map.Entry;

Import com.google.gson.JsonArray;

Import com.google.gson.JsonElement;

Import com.google.gson.JsonObject;

Import com.google.gson.JsonParser;

Import com.google.gson.JsonPrimitive;

Import entity.ArrayType;

Import entity.Json2JavaElement;

Public class JsonUtils {

Public static void main(String[] args) {

parseJson2Java();

}

/**

* Convert json string to corresponding javabean

* Usage:

* Copy the json string to the /Json/JsonString.txt file in this project, and then call this method.

* will generate a corresponding JavaBean class in /Json/JsonBean.java in this project

* Note:

* If there is a null or empty collection in the json string [] which cannot determine the type, the Object type will be used uniformly.

*/

Public static void parseJson2Java() {

/// read json string

String string = FileUtils.readToString(new File("Json\\JsonString.txt"), "UTF-8");

// parse to get the entire json structure collection

JsonParser parser = new JsonParser();

JsonElement element = parser.parse(string);

JsonObject jo = element.getAsJsonObject();

ListjsonBeanTree = getJsonBeanTree(jo);

/ / Use the obtained json structure collection to create the corresponding javabean file content

String javaBeanStr = createJavaBean(jsonBeanTree);

// Write the generated content to a file

FileUtils.writeString2File(javaBeanStr, new File("Json\\JsonBean.java"));

}

/**

* Create a corresponding javabean class string based on the parsed data

*

* @param jsonBeanTree parsed data collection

* @return generated javabean class string

*/

Private static String createJavaBean(ListjsonBeanTree) {

StringBuilder sb = new StringBuilder();

// Whether to include a custom subclass

Boolean hasCustomeClass = false;

ListcustomClassNames = new ArrayList();

Sb.append("public class JsonBeans {");

// Use iterator traversal because there is a remove operation during the loop

Iteratoriterator = jsonBeanTree.iterator();

While(iterator.hasNext()) {

Json2JavaElement j2j = iterator.next();

// Save the custom class name to the collection, note that the included ones are no longer added

If(j2j.getCustomClassName() != null && !customClassNames.contains(j2j.getCustomClassName())) {

customClassNames.add(j2j.getCustomClassName());

}

If(j2j.getParentJb() != null) {

/ / If there is a parent, it is a custom subclass, set the identifier to do no other operations

hasCustomeClass = true;

} else {

/ / If not a custom subclass, generate a variable declaration statement based on the type name and control object name

// private TextView tv_name;

Sb.append("private")

.append(getTypeName(j2j))

.append(" ")

.append(j2j.getName())

.append(";");

160W Street Lights Led Driver

160W Street Lights Led Driver



With global manufacturing standards and various certifications including CE, UL,FCC, TUV and SAA, our led driver products are sold in domestic market and are exported to various international markets including US, UK, France, Germany, Australia, Africa, Korea etc. We offer a wide range of LED lighting power solutions which includes LED Street Lighting or System, LED Lams, LED linear etc. At the same time Saving energy and Maximize beauty of your workplaace drive by our designing Switching power supply!

Most Application: LED street light,outdoor for waterproof,

Advantage: High Power Led Driver,safety and stability, high pressure test protection, short circuit protection, anti-lightning strong, safe level Certification, UL TUV FCC, etc. certification.

Parameter:

Input ovltage:100-277V

Output voltage(different range):24-38V/30-42V/36-54V/45-76V/72-143V

Current:100-5000mA

Power factor:>0.95

THD:<15%

Dimming: 0-10V/PWM/RX

Housing: Aluminum

FD-160H

What's the benefits of Fahold Linear Lights driver?

  • Standard Linear Lighting
  • Cost-effective light-line solution for industry,commercial and other applications
  • Good quality of light with 5years warranty, EMC, EMI, safety SELV design
  • Easy to order and install,requiring less time,reducing packaging waste and complexity
  • Flexible solution
FAQ:
Question 1:Are you a factory or a trading company?
Answer: We are a factory.
Question 2: Payment term?
Answer: 30% TT deposit + 70% TT before shipment,50% TT deposit + 50% LC balance, Flexible payment
can be negotiated.
Question 3: What's the main business of Fahold?
Answer: Fahold focused on LED controllers and dimmers from 2010. We have 28 engineers who dedicated themselves to researching and developing LED controlling and dimming system.
Question 4: What Fahold will do if we have problems after receiving your products?
Answer: Our products have been strictly inspected before shipping. Once you receive the products you are not satisfied, please feel free to contact us in time, we will do our best to solve any of your problems with our good after-sale service.



Led High Power,Electronic Led Converter,Ac Led Driver

ShenZhen Fahold Electronic Limited , https://www.fahold.net