package com.liang.common.utils;

import com.fasterxml.jackson.core.io.JsonEOFException;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.jar.JarException;

/**
 * @Author ly
 * @Date 2024/5/15 11:08
 * @Version 1.0
 */
public class GetJsonIDUtil {

    public int getIdFromJson(String jsonStr) {
        try {
            JSONArray jsonArray = new JSONArray(jsonStr);
            JSONObject jsonObject = jsonArray.getJSONObject(0);
            return jsonObject.getInt("id");

        } catch (Exception a) {
            a.printStackTrace();

            // Assuming you need the first item

        }
        return 0;
    }
}