加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

利用JSONObject转换字符串String为List

发布时间:2020-12-16 19:46:33 所属栏目:百科 来源:网络整理
导读:其中使用JSONObject: 这里是: import com.alibaba.fastjson.JSONArray ; import com.alibaba.fastjson.JSONObject ; 代码如下: package com.xx.util ; import com.alibaba.fastjson.JSONArray ; import com.alibaba.fastjson.JSONObject ; import java.uti

其中使用JSONObject:

这里是:

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;


代码如下:

package com.xx.util;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.List;

/**  * @author yangxin-ryan  */ public class StringUtil {


    /**  * 测试的man方法  * @param args  */  public static void main(String[] args) {
        // 原始字符串数据
        String str = "[{"metric":"base.app.dns.1m","tags":{"carrier":"liantong","access":"wifi","host":"order.api.xx.com","region":"china","version":"2.8","platform":"ssss","url":"/s/s/x/x/c"},"aggregateTags":[],"dps":{"1519698960":1000.0}}]";
        // 字符串转换为JSON数组
        List<JSONObject> str1 = JSONArray.parseArray(str).toJavaList(JSONObject.class);
        System.out.println(str1);
    }
}

结果:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读