我想创建一个像
这样的 json 有效负载 {
"email":"dautpure@gmail.com",
"validators": ["SyntaxValidator", "MXValidator", "ListDetectiveValidator"]
}
我编写了以下代码:
<小时/>package com.forcelocker.loaddata;
import com.google.gson.JsonObject;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class validateEmail
{
public static String CheckingURL = "h_ttps://abc.com/address/v1/validateEmail";
private static final String Content_Type ="application/json";
public static Boolean CheckEmail(String Email,String Token) throws UnirestException
{
Boolean IsmailOk=false;
String Authorization = "Bearer "+Token;
JsonObject payload = new JsonObject();
payload.addProperty("email", Email);
HttpResponse<String> response = Unirest.post(CheckingURL)
.header("Content-Type", Content_Type)
.header("Authorization", Authorization)
.body(payload).asString();
return IsmailOk;
}
}
但我不知道如何将 validator 放入可以保存逗号分隔值的 JSON 中
任何帮助都会很棒。
最佳答案
怎么样
payload.addProperty("validator", new String [] {"SyntaxValidator", "MXValidator", "ListDetectiveValidator"});
关于java json 一个变量有多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58432312/