28 lines
790 B
Java
28 lines
790 B
Java
package com.example.sso;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import org.junit.Test;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
import java.util.Collections;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
|
|
|
|
@SpringBootTest
|
|
class SsoApplicationTests {
|
|
|
|
@Test
|
|
void context() {
|
|
String json = "[{\"name\":\"1111\",\"code\":\"123\"},{\"name\":\"1111\",\"code\":\"123\"},{\"name\":\"1234\",\"code\":\"111\"}]";
|
|
List list = JSONObject.parseArray(json);
|
|
HashSet hs = new HashSet(list);
|
|
String jsonSet = JSON.toJSONString(hs);
|
|
JSONArray newjsonarray= new JSONArray(Collections.singletonList(jsonSet));
|
|
System.out.println(newjsonarray);
|
|
}
|
|
|
|
}
|