java json 一个变量有多个值

标签 java json

我想创建一个像

这样的 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/

相关文章:

java - Gson:JsonSyntaxException:应为 BEGIN_OBJECT 但为 STRING

javascript - 使用 GitHub api 在 dojo 中执行 PUT 更新返回 400 : problems parsing JSON

php - 将 JSONArray 从 Android 传递到 PHP

java - 安卓开发 : AlertDialog with SurfaceView

java - 如何使 JavaFX ComboBox 中没有重复项

Java 在文件上设置访问日期

json - 括号: Custom Theme

json - 如何用 JSON 树中的相同键替换所有值

java - android:生成随机数而不重复

java - 使用 CallableStatements 枚举作为针对 SQL 注入(inject)的白名单