Android uses network technology, usage of WebView, usage of OkHttp, parsing XML format data (Pull, SAX), parsing JSON format data (JSONObject, GSON)

1. Usage of WebView <WebView android:id=”@ + id/Web_view” android:layout_width=”wrap_content” android:layout_height=”wrap_content” tools:layout_editor_absoluteX=”165dp” tools:layout_editor_absoluteY=”58dp” /> public class MainActivity extends AppCompatActivity {<!– –> @Override protected void onCreate(Bundle savedInstanceState) {<!– –> super.onCreate(savedInstanceState); setContentView(R. layout. activity_main); WebView webView = findViewById(R.id.Web_view); Button button = findViewById(R.id.button); //Let WebView support js script webView.getSettings().setJavaScriptEnabled(true); //When it is necessary to jump from one webpage to […]

When converting fastjson2 to a string JSONObject.toJSONString, there is a problem that the first letter of the field is lowercase

The field names in the database and entity classes are capitalized. After JSONObject.toJSONString is converted into a string for output, the first letter becomes lowercase Solution: Output the first letter of the field name of the database entity class generated by MyBatisGenerator in uppercase according to the original database field, and then add @JsonProperty(value= “field […]

java-Mybatis custom JsonObjectTypeHandler dynamically parses database JSON type data

java-Mybatis custom JsonObjectTypeHandler dynamically parses database JSON type data Environment jdk 1.8 springboot 1.5.6 PostgreSQL 14.5 mybatis 3.53 postgresql 42.2.1 Introduction Mainstream databases support the Json data type, but Mybatis does not support it well, so you must write your own TypeHandler for processing. Recently, when using the pg library, I encountered the problem of […]

JSONObject Conversion: A Tool to Simplify JSON Data Processing

JSONObject conversion: a powerful tool to simplify JSON data processing In modern software development, processing JSON (JavaScript Object Notation) data has become a common task. As a lightweight data exchange format, JSON is widely used in data transmission of web applications, mobile applications and various APIs. In the field of Java development, JSONObject is a […]

Serialization error java.io.NotSerializableException: net.sf.ezmorph.primitive.CharMorpher reported after net.sf.json.JSONObject forced conversion

1. Scene 1. Convert net.sf.json.JSONObject to entity object 2. Serialize the List attribute of the entity object (the entity class of the List attribute implements the Serializable interface) 3. Serialization error-java.io.NotSerializableException: net.sf.ezmorph.primitive.CharMorpher 2. Error message java.io.NotSerializableException: net.sf.ezmorph.primitive.CharMorpher at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348) at java.util.ArrayList.writeObject(ArrayList.java:766) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1140) at […]

This article lets you use JSONObject and JSONArray proficiently

Depends Import Ali’s fastjson dependency. <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.78</version> </dependency> Type conversion Conversion between String and JSON Use JSONObject.parseObject(String str) to convert a string into a JSONObject object. This method supports JSON strings. The JSON string format is as follows: Writing method one: {<!– –> “code”:”1″, “status”:”success”, “target”:”One million annual income”, “msg”:{<!– –> “seq”:”20230424″, “weather”:”Sunny”, […]

Springboot integrates dom4j to parse xml string to JSONObject

Foreword This article only introduces the way of using dom4j and fastjson, because it is used more on weekdays. The old json can also be transferred, and the XML is also packaged, but this article will not introduce it. Text ①Add pom dependency <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency> ② Tool class MyXmlUtil.java import com.alibaba.fastjson.JSONArray; import […]

[Solved] jsonObject.fromObject() report red solution

Add the following dependencies <!– json –> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.28</version> </dependency> <!– The jar package that the JSONObject object depends on –> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.9.3</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2.1</version> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>net.sf.ezmorph</groupId> <artifactId>ezmorph</artifactId> <version>1.0.6</version> </dependency> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.2.3</version> <classifier>jdk15</classifier><!– specify jdk […]

[Solved] fastjson reports an error: com.alibaba.fastjson.JSONObject cannot be cast to xxxx

There is a StockData object, under normal circumstances, the json string conversion object should be: StockData stockData = JSONObject.parseObject(str, StockData.class); There is no problem in this way, and it is normal for get to obtain parameters, but if the object is a generic type (such as StockData), the conversion as above can also be converted, […]