集合转json json转集合

集合转json json转集合

导包

xml 复制代码
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

集合转json

java 复制代码
import org.springframework.data.redis.core.StringRedisTemplate;

// 注入StringRedisTemplate
	@Autowired
    private StringRedisTemplate redisTemplate;


// 在某个方法里将
public void redisMenthod(){
    // 拿到集合 ZtAuthResource是我的实体类
    List<ZtAuthResource> list = list();
    
    // 存入redis
    redisTemplate.opsForValue().set("resourceList", JSON.toJSONString(list));
}

json转集合

java 复制代码
// 引的包
import com.alibaba.fastjson.JSONArray;

List<ZtAuthResource> redisResourceList = JSONArray.parseArray(redisResourceListStr, ZtAuthResource.class);
相关推荐
Snowbowღ20 小时前
OpenAI / GPT-4o:Python 返回结构化 / JSON 输出
python·json·openai·api·gpt-4o·pydantic·结构化输出
林戈的IT生涯1 天前
MySQL5.7中增加的JSON特性的处理方法JSON_EXTRACT和JSON_ARRAY_APPEND以及MYSQL中JSON操作的方法大全
json·mysql5.7·json特性·json_extract·mysql中json操作方法
敲代码不忘补水1 天前
Python 项目实践:简单的计算器
开发语言·python·json·项目实践
亚林瓜子2 天前
Jackson注解屏蔽某些字段读取权限
spring·json·jackson
不惑_2 天前
最佳实践 · 如何高效索引MySQL JSON字段
java·mysql·json
天上掉下来个程小白3 天前
请求响应-05.请求-日期参数&JSON参数
spring boot·json
敲代码不忘补水3 天前
Python Pickle 与 JSON 序列化详解:存储、反序列化与对比
开发语言·python·json
jackletter3 天前
c#:System.Text.Json 的使用四(如何忽略[JsonPropertyName])
c#·json·序列化
A 八方3 天前
Python JSON
开发语言·python·json
小故渊4 天前
JSON对象
运维·服务器·json