The JSON data format is like this:
JSON is a lightweight data exchange format that uses two structures, objects and arrays, to represent data. Objects are used to represent key-value pairs, while arrays are used to represent ordered lists of values. Therefore, the data format of JSON is actually a composite structure of objects and arrays. This simple and flexible format makes JSON a widely used choice for data interaction and storage.
Your example JSON data is a name/value pair, in which there is only one variable name of "wegInstLt", and the value is an array containing one entry. Assume var info={"wegInstLt":[{"billTypeCode":"0","channelId":530,"channelKind":"03","isHaveBillDate":"0","isHavePayAmount":"0"," isLeePay":"0","isPrePay":"1","wiliCode":"1238","wiliItem":"00","wiliName":"Harbin Water Company","wltiId":10345}]} ; To get "Harbin Water Company" you can write like this:
info.wegInstLt[0].wiliName
I hope this helps, and I wish you a happy life!
Convert JSON array to JAVA
org.json.JSONObject
You can use this package to achieve your needs. Search this package on the Internet. It contains some methods that can convert a JSON string into a JSONObject object and vice versa. You can check its API documentation for specific details.
How about your string?
public static void main(String[] args) throws JSONException {
String sJson = "[{'gwcxxid':'1','spsl':'2'},{'gwcxxid':'1','spsl':'2'},{'gwcxxid':' 3','spsl':'4'}]";
JSONArray jsonArray = new JSONArray(sJson);
int iSize = jsonArray.length();
System.out.println("Size:" iSize);
for (int i = 0; i
JSONObject jsonObj = jsonArray.getJSONObject(i);
System.out.println("[" i "]gwcxxid=" jsonObj.get("gwcxxid"));
System.out.println("[" i "]spsl=" jsonObj.get("spsl"));
System.out.println();
}
}
How to convert json into an array in java
Use native parsing:
String json = "...";
//Traverse the values in the array to get each independent object, then get the corresponding value and set it to the declared object. Finally, after the object is created, it is added to the collection, such as the fragment in my own code:
for (int j = 0; j
obj = array.getJSONObject(j);
Data data = new Data();
mDataList.add(data);
}
Array declaration
In the declaration format of the array, "data type" is the data type of the declared array element, which can be any data type in the Java language, including simple types and structural types. "Array name" is a name used to unify these same data types, and its naming rules are the same as those of variables.
After the array is declared, the next step is to allocate the memory required for the array. At this time, the operator new must be used. The "number" tells the compiler how many elements the declared array should store, so the new operator The symbol tells the compiler to allocate a space in memory for the array according to the number in the brackets. The method of allocating memory space for array elements using the new operator is called dynamic allocation.
Reference for the above content: Encyclopedia-Array
The above is the detailed content of Understand the basic structure of the JSON data format. For more information, please follow other related articles on the PHP Chinese website!

Do you encounter nvvsvc.exe runtime error on Startup? What’s worse, some of you might end up with a black screen. Therefore, it is urgent for you to remove this error as soon as possible. In this guide on php.cn Website, we gathered some feasible sol

You must be familiar with the Windows P shortcut if you have more than one monitor. However, the Windows P not working properly might happen occasionally. If you are facing this problem, this post from php.cn can help you indeed.

The issue of Acronis clone failed to read data from the disk often appears during the cloning process. What should you do when confronted with this boring issue? Try to fix it. Or, you can run an alternative to Acronis True Image – a php.cn software

When you try to access a Word document from a folder, you may get an error that just says "Not implemented" after clicking it. This post from php.cn introduces how to fix the “file upload not implemented” issue.

Microsoft has invested a lot of manpower and financial resources in AI and has achieved great results. In this post, php.cn will talk about AI in Windows, including AI tools and features in Windows 11 and Windows 10.

KB5034441 fails to install with the error code 0x80070643? A PowerShell script for Windows 10 0x80070643 from Microsoft helps to automate updating the WinRE partition to fix the BitLocker Security Feature Bypass vulnerability. php.cn guides on you ho

Contra: Operation Galuga is a newly released shooter video game published by Konami. Here this post on php.cn Software focuses on Contra: Operation Galuga save file location and explains how to back up Contra: Operation Galuga save files.

Microsoft Word delivers many useful features for all of us, including highlighting text. However, some people recently faced a problem that they can’t highlight text in Microsoft Word. This problem causes inconvenience to them. If you are one of them


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools