JSON is the first data structure. To put it bluntly, it is a description of data. It just appeared to replace XML. Unfortunately, it does not exist, but as a configuration file, it is very good because it It is small and flexible, and describes the data very well, so it is more convenient to transmit data on the network.
Please remember the description form of data in JSON. Since it is a form, what is its data form like:
The description of the object is: {} This represents jsonobject (json object)
Description of the array Is: [] represents jsonarray (json array)
The description of the attribute or value is: ""
The description between the connections is: :
ExampleThe format is like this:
{ “ret”: 1, “data”: [ { “id”: “8289”, “title”: “油焖大虾”, “collect_num”: “1596”, “food_str”: “大虾 葱 生姜 植物油 料酒”, “num”: 1596 },
The first method: native analysis
First of all, we need to analyze the format of json, here first is a json object ( That is, JsonObject), there is also a json array (that is, JsonArray) nested inside, and there is a json object in jsonarray. Once the analysis is clear, you can parse it. Of course, the best thing is to create an entity class bean corresponding to json.
The result here is the json string returned by the network request.
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.getJSONArray(“data”);
for (int j = 0; j JSONObject jsonObject2 = jsonArray.getJSONObject(j);
String id = jsonObject2.getString(“id”);
String title = jsonObject2.getString(“title”);
String pic = jsonObject2. getString("pic");
String collect_num = jsonObject2.getString("collect_num");
String food_str = jsonObject2.getString("food_str");
String num = jsonObject2.getString("num" );
Log.e(“json——->”, id ”,” title ”,” pic ”,” collect_num ”,” food_str ”,” num);
The second parsing method: Gson parsing
Gson parsing requires downloading the gson.jar package.
The analysis here requires generating entity classes for json. If you are a beginner, it is recommended to write it by hand. If you are familiar with it, you can use the plug-in GsonFormat in Android Studio to automatically generate it.
Parsing is just one sentence:
MenuBean menuBean = new Gson().fromJson(result, MenuBean.class);
Log.e(“MenuBean—–>”, menuBean.getRet() "");
The third parsing method: FastJson is similar to Gson.
MenuBean menuBean = JSON.parseObject(result,MenuBean.class);
Log.e(“MenuBean—–>”, menuBean.getRet() ”“);
Log.e (“MenuBean—–>”, menuBean.getData().get(0).getPic() ”“);
The fourth parsing method: JackJson parsing, also similar to the above
MenuBean menuBean;
menuBean = new ObjectMapper().readValue(result, MenuBean.class);
Log.e(“MenuBean—–>”, menuBean.getRet() ””) ;
Log.e(“MenuBean—–>”, menuBean.getData().get(0).getPic() ”“);
The above is the detailed content of How to get data in json. For more information, please follow other related articles on the PHP Chinese website!

1、先看看效果图,可以自行选择展示效果2、这是我在vue3项目中使用的JSON编辑器,首先引入第三方插件npminstalljson-editor-vue3yarnaddjson-editor-vue33、引入到项目中//导入模块importJsonEditorVuefrom'json-editor-vue3'//注册组件components:{JsonEditorVue},4、一般后端返回的是会将JSON转为String形式我们传给后端也是通过这种形式,就可以通

控制json序列化/反序列化1.@JsonIgnoreProperties的用法@JsonIgnoreProperties(value={"prop1","prop2"})用来修饰Pojo类,在序列化和反序列化的时候忽略指定的属性,可以忽略一个或多个属性.@JsonIgnoreProperties(ignoreUnknown=true)用来修饰Pojo类,在反序列化的时候忽略那些无法被设置的属性,包括无法在构造子设置和没有对应的setter方法.2.@Js

Java调用接口获取json数据保存到数据库1.在yml文件中配置自己定义的接口URL//自己定义的JSON接口URLblacklist_data_url:接口URL2.在Controller中添加请求方法和路径/***@Title:查询*@Description:查询车辆的记录*@Author:半度纳*@Date:2022/9/2717:33*/@GetMapping("/Blacklist")publicvoidselectBlacklist(){booleana=imB

本篇文章给大家带来了关于JWT的相关知识,其中主要介绍了什么是JWT?JWT的原理以及用法是什么?感兴趣的朋友,下面一起来看一下吧,希望对大家有帮助。

JSONSchemaJSONSchema是用于验证JSON数据结构的强大工具,Schema可以理解为模式或者规则。JsonSchema定义了一套词汇和规则,这套词汇和规则用来定义Json元数据,且元数据也是通过Json数据形式表达的。Json元数据定义了Json数据需要满足的规范,规范包括成员、结构、类型、约束等。JSONSchema就是json的格式描述、定义、模板,有了他就可以生成任何符合要求的json数据json-schema-validator在java中,对json数据格式的校验,使用

PHP作为一种常见的编程语言,在web开发中使用广泛,其与前端交互的方式也多种多样。其中,输出Json数据是一种常见的交互方式,但有时候会碰到Json无法解析的问题。为什么会出现无法解析的情况呢?下面列举了几个可能的原因。

一、@RestController注解在SpringBoot中的Controller中使用@RestController注解即可返回JSON格式的数据。@RestController注解包含了@Controller和@ResponseBody注解。@ResponseBody注解是将返回的数据结构转换为JSON格式。@Target({ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documented@Controller@Respons

当我们处理数据时经常会遇到将XML格式转换为JSON格式的需求。PHP有许多内置函数可以帮助我们执行这个操作。在本文中,我们将讨论将XML格式转换为JSON格式的不同方法。


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

Dreamweaver CS6
Visual web development tools

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.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
