gpt4 book ai didi

c# - 将重复键添加到 NameValueCollection

转载 作者:行者123 更新时间:2023-11-30 13:57:21 26 4
gpt4 key购买 nike

我读过 NameValueCollection 允许添加重复的键,但是当我尝试使用它时,情况似乎并非如此。

我的代码

using (var wb = new WebClient())
{
var data = new NameValueCollection();
var sourceData = (List<Dictionary<string, object>>)dic["mapData"];
var countSource = sourceData.Count;

foreach (var item in (List<Dictionary<string, object>>)dic["mapData"])
{
data.Add("pp", item["Latitude"].ToString() + "," + item["Longitude"].ToString());
}

var dataCount = data.Count;
var response = wb.UploadValues(@"http://dev.virtualearth.net/REST/V1/Imagery/Map/road/?mapArea=" + swLat.ToString() + "," + swLong + "," + neLat + "," + neLong + "&mapSize=800,600&key=" + key, "POST", data);

return this.LargeJson(new { imageData = CreateBase64Image(response) });
}

我在观察

我的源数据包含 36 个项目

watches

我正在遍历 sourceData 并将项目添加到我的 NameValueCollection 数据中,并添加具有相同键“pp”的项目

我期望在我的数据 NameValueCollection 中有 36 个项目,但我只得到 1 个并且我的所有值都附加到同一个键。

我错过了什么?

最佳答案

这是预期的行为 - 请参阅 the documentation :

If the specified key already exists in the target NameValueCollection instance, the specified value is added to the existing comma-separated list of values in the form "value1,value2,value3". The values are associated with the same key in the target NameValueCollection instance.

关于c# - 将重复键添加到 NameValueCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21590778/

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