gpt4 book ai didi

android - 如何将arraylist添加到Map中

转载 作者:行者123 更新时间:2023-11-30 00:10:12 25 4
gpt4 key购买 nike

我正在尝试模仿这种结构以将数据发布到 mailchimp,我正在使用 volley

{
"email_address": "testchimp@gmail.com",
"status": "subscribed",
"merge_fields": {
"FNAME": "testmailchimp",
"LNAME": "testingit",
}
}

我已经这样做了,但是我需要添加 FNAME 和 LNAME,但我不知道如何做对

 @Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("email_address","testchimp@gmail.com");
params.put("status","unsubscribed");
//here i want to add the arraylist FNAME and LNAME
return params;
}

Solved my problem with this

final JSONObject jsonBody = new JSONObject("{\"email_address\":\"mailchimptester@gmail.com\"," +
"\"status\":\"unsubscribed\"," +
"\"merge_fields\":{\"FNAME\":\"test\",\"LNAME\":\"teste\"}}");

所以有了这个我可以在没有 map 的情况下按照我想要的方式做 json,然后在这里验证它 https://jsonlint.com/

最佳答案

它不是一个ArrayList,而是一个Map。您可以使用此代码来完成

HashMap<String,String> merge_fields = new HashMap<>();
merge_fields.put("FNAME","testmailchimp");
merge_fields.put("LNAME","testingit");
String merge_fields_param = new JSONObject(merge_fields).toString();
params.put("merge_fields",merge_fields_param);

关于android - 如何将arraylist添加到Map中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48268305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com