java alibaba fastJson 遍历数组json

import java.util.*;
import com.alibaba.fastjson.*;
public class Test {
	public static void main(String[] args) {
	    //方法1
	    String json = "[{\"companyId\":\"111111111\",\"companyName\":\"Huuuu\",\"_uid\":10,\"_index\":0,\"_state\":\"modified\"},{\"companyId\":\"000000000000000000\",\"companyName\":\"cx01\",\"_uid\":11,\"_index\":1,\"_state\":\"modified\"},{\"companyId\":\"9999999999999\",\"companyName\":\"ttt\",\"_uid\":12,\"_index\":2,\"_state\":\"modified\"}]";
	    List<HashMap> list =JSON.parseArray(json, HashMap.class);
	    for(int i=0;i<list.size();i++){
	      System.out.println(list.get(i).get("companyId"));;
	    }
	    //方法2
	    /*
	    JSONArray jarr = JSONArray.parseArray(json);
	    for (Iterator iterator = jarr.iterator(); iterator.hasNext();) {
	      JSONObject job = (JSONObject) iterator.next();
	      System.out.println(job.get("companyId").toString());
	    }*/
	}
}
    String str = "[\"\\/static\\/upload\\/1539863638_0.png\"]";
    JSONArray array = new JSONArray().parseArray(str);

        if(null!=array){
            array.set(0, "----------"+array.get(0));
            for (Iterator iterator = array.iterator(); iterator.hasNext();) {
              System.out.println(iterator.next());
            }
        }

原文地址:https://www.cnblogs.com/phpfangzhan/p/9813001.html

时间: 2024-08-29 13:36:04

java alibaba fastJson 遍历数组json的相关文章

Java:JSTL遍历数组,List,Set,Map

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ page import="java.util.*"

java-com.alibaba.fastjson快速处理json字符串转成list类型

public static List<Map<String, String>> jsonToList(String json) { JSONReader reader = new JSONReader(new StringReader(json));// 已流的方式处理,这里很快 reader.startArray(); List<Map<String, String>> rsList = new ArrayList<Map<String, St

42-字符串到json 的错误 com.alibaba.fastjson.JSONObject cannot be cast to java.lang.String

json: {"updated_at":1551780617,"attr":{"uptime_h":3,"uptime_m":17},"did":"GBBxjJYAxE4apkxwEzR3"} Map rMap = (Map) JSON.parse("{"updated_at":1551780617,"attr":{"uptim

阿里巴巴 fastjson-1.2.12.jar json解析异常java.lang.ClassFormatError: Invalid method Code length 66865 in class file com/alibaba/fastjson/serializer/ASMSerializer_6_UserKdlb

承接上篇:fastjson反序列化LocalDateTime失败的问题java.time.format.DateTimeParseException: Text '2019-05-24 13:52:11' could not be parsed at index 10 之前在线上用的版本是fastjson-1.2.7.jar 一切正常,更换以后时间解析看似一切正常. 因为在系统中设计json反序列化的地方比较多,刚刚放到生产环境,app那边的接口报错了 java.lang.ClassFormat

JSON parse error: default constructor not found. class java.time.YearMonth; nested exception is com.alibaba.fastjson.JSONException: default constructor not found. class java.time.YearMonth

java8新出的YearMonth可以方便的用来表示某个月.我的项目中使用springmvc来接收YearMonth类型的数据时发现 x-www-from-urlencoded 格式的数据可以使用"2018-12"的类型接收,但是在post请求中 接收application/json的数据时出现以下错误 2020-02-18 11:18:25.284 WARN 16212 --- [nio-8090-exec-2] .w.s.m.s.DefaultHandlerExceptionRes

java遍历复杂json字符串获取想要的数据

https://blog.csdn.net/qq_34309663/article/details/80508125 java如何解析复杂的json数据关于json处理的包有好几个,比如jackson.Gson.Fastjson.Gson是谷歌做的,功能强大:Fastjson是阿里巴巴做的,性能更快.具体用哪个,开心就好.我这里两个都没用,用的是java的一个类库-json-lib.如果你用的是maven构建的项目,添加依赖请注意加上JDK版本15,详情请戳这里ok,多的不说了,让我们直接来解析

com.alibaba.fastjson和net.sf.json的区别

JSON有两种结构 json简单说就是javascript中的对象和数组,所以这两种结构就是对象和数组两种结构,通过这两种结构可以表示各种复杂的结构 1.对象:对象在js中表示为“{}”括起来的内容,数据结构为 {key:value,key:value,...}的键值对的结构,在面向对象的语言中,key为对象的属性,value为对应的属性值,所以很容易理解,取值方法为对象.key 获取属性值,这个属性值的类型可以是数字.字符串.数组.对象几种. 2.数组:数组在js中是中括号“[]”括起来的内容

JSON工具类库: alibaba/fastjson 使用记录

JSON工具类库: alibaba/fastjson 使用记录 一.了解JSON JSON标准规范中文文档: http://www.json.org/json-zh.html 最佳实践:http://kimmking.github.io/2017/06/06/json-best-practice/ (JSON的高级使用,特别十分有参考价值) 二.项目地址和Wiki: Git地址: https://github.com/alibaba/fastjson Wiki:https://github.co

com.alibaba.fastjson.JSON对类对象的序列化与反序列化

1. 目标 把类的对象存储到字符串可存储 2. 类定义 public interface JsonInterface { } mport com.alibaba.fastjson.JSON; import lombok.Getter; import lombok.Setter; @Setter @Getter public class JsonVo implements JsonInterface { private String id; private String name; public