集合转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);
相关推荐
上海合宙LuatOS6 天前
LuatOS核心库API——【json 】json 生成和解析库
java·前端·网络·单片机·嵌入式硬件·物联网·json
敲代码的柯基6 天前
一篇文章理解tsconfig.json和vue.config.js
javascript·vue.js·json
万物得其道者成7 天前
前端大整数精度丢失:一次踩坑后的实战解决方案(`json-bigint`)
前端·json
Ai runner7 天前
Show call stack in perfetto from json input
java·前端·json
ID_180079054737 天前
淘宝商品详情API请求的全场景,带json数据参考
服务器·数据库·json
恒云客8 天前
python uv debug launch.json
数据库·python·json
wanderist.8 天前
从 TCP 到 JSON:一次 FastAPI + LLM 生产环境 “Unexpected end of JSON input” 的底层剖析
tcp/ip·json·fastapi
享誉霸王9 天前
15、告别混乱!Vue3复杂项目的规范搭建与基础库封装实战
前端·javascript·vue.js·前端框架·json·firefox·html5
今心上9 天前
关于json的理解测试!!
开发语言·json
强子感冒了10 天前
JSON和XML学习笔记
xml·学习·json