Asp.net 有人可以在.net中使用json数组吗?
我正在尝试将我的应用程序与MercadolibreAPI集成。我可以毫无问题地列出一个新项目,但当我尝试插入图片数组时,集成不起作用。 错误消息:Asp.net 有人可以在.net中使用json数组吗?,asp.net,arrays,json,Asp.net,Arrays,Json,我正在尝试将我的应用程序与MercadolibreAPI集成。我可以毫无问题地列出一个新项目,但当我尝试插入图片数组时,集成不起作用。 错误消息: {"message":"body.invalid_field_types","error":"[invalid property type: [pictures] expected List but was null value: [pictures:[[source:http://www.nichepursuits.com/wp-content/u
{"message":"body.invalid_field_types","error":"[invalid property type: [pictures] expected List but was null value: [pictures:[[source:http://www.nichepursuits.com/wp-content/uploads/2014/02/buy-websites.jpg], [source:http://thumb9.shutterstock.com/display_pic_with_logo/639229/176602316/stock-vector-best-buy-rubber-stamp-red-icon-isolated-on-white-background-vector-illustration-176602316.jpg]]]]","status":400,"cause":[]}
当我尝试使用下面的第二个选项时,VisualStudio显示了一个编译错误
我已经测试了很多声明,但都失败了
暂定1:
IRestResponse r = m.Post("/items", ps, new
{
title = _item.title,
category_id = _item.category_id,
price = _item.price,
currency_id = _item.currency_id,
available_quantity = _item.available_quantity,
buying_mode = _item.buying_mode,
listing_type_id = _item.listing_type_id,
condition = _item.condition,
description = _item.description,
warranty = _item.warranty,
pictures = new {pictures = new []
{
new {source = "http://www.nichepursuits.com/wp-content/uploads/2014/02/buy-websites.jpg"},
new {source = "http://thumb9.shutterstock.com/display_pic_with_logo/639229/176602316/stock-vector-best-buy-rubber-stamp-red-icon-isolated-on-white-background-vector-illustration-176602316.jpg"}
}}
});
暂定2:
IRestResponse r = m.Post("/items", ps, new
{
title = _item.title,
category_id = _item.category_id,
price = _item.price,
currency_id = _item.currency_id,
available_quantity = _item.available_quantity,
buying_mode = _item.buying_mode,
listing_type_id = _item.listing_type_id,
condition = _item.condition,
description = _item.description,
warranty = _item.warranty,
pictures = [{"Source":"Value"},{"Source":Value2}]
});
pictures = new {pictures = new []
{
new {source = "http://www.nichepursuits.com/wp-content/uploads/2014/02/buy-websites.jpg"},
new {source = "http://thumb9.shutterstock.com/display_pic_with_logo/639229/176602316/stock-vector-best-buy-rubber-stamp-red-icon-isolated-on-white-background-vector-illustration-176602316.jpg"}
}}
pictures = new[]
{
new { source = "http://www.nichepursuits.com/wp-content/uploads/2014/02/buy-websites.jpg" },
new { source = "http://thumb9.shutterstock.com/display_pic_with_logo/639229/176602316/stock-vector-best-buy-rubber-stamp-red-icon-isolated-on-white-background-vector-illustration-176602316.jpg"}
}
C#对JSON数组一无所知,幸运的是,它有自己的数组
您的代码:
IRestResponse r = m.Post("/items", ps, new
{
title = _item.title,
category_id = _item.category_id,
price = _item.price,
currency_id = _item.currency_id,
available_quantity = _item.available_quantity,
buying_mode = _item.buying_mode,
listing_type_id = _item.listing_type_id,
condition = _item.condition,
description = _item.description,
warranty = _item.warranty,
pictures = [{"Source":"Value"},{"Source":Value2}]
});
pictures = new {pictures = new []
{
new {source = "http://www.nichepursuits.com/wp-content/uploads/2014/02/buy-websites.jpg"},
new {source = "http://thumb9.shutterstock.com/display_pic_with_logo/639229/176602316/stock-vector-best-buy-rubber-stamp-red-icon-isolated-on-white-background-vector-illustration-176602316.jpg"}
}}
pictures = new[]
{
new { source = "http://www.nichepursuits.com/wp-content/uploads/2014/02/buy-websites.jpg" },
new { source = "http://thumb9.shutterstock.com/display_pic_with_logo/639229/176602316/stock-vector-best-buy-rubber-stamp-red-icon-isolated-on-white-background-vector-illustration-176602316.jpg"}
}
这实际上不是数组,而是匿名对象。
尝试重写它:
IRestResponse r = m.Post("/items", ps, new
{
title = _item.title,
category_id = _item.category_id,
price = _item.price,
currency_id = _item.currency_id,
available_quantity = _item.available_quantity,
buying_mode = _item.buying_mode,
listing_type_id = _item.listing_type_id,
condition = _item.condition,
description = _item.description,
warranty = _item.warranty,
pictures = [{"Source":"Value"},{"Source":Value2}]
});
pictures = new {pictures = new []
{
new {source = "http://www.nichepursuits.com/wp-content/uploads/2014/02/buy-websites.jpg"},
new {source = "http://thumb9.shutterstock.com/display_pic_with_logo/639229/176602316/stock-vector-best-buy-rubber-stamp-red-icon-isolated-on-white-background-vector-illustration-176602316.jpg"}
}}
pictures = new[]
{
new { source = "http://www.nichepursuits.com/wp-content/uploads/2014/02/buy-websites.jpg" },
new { source = "http://thumb9.shutterstock.com/display_pic_with_logo/639229/176602316/stock-vector-best-buy-rubber-stamp-red-icon-isolated-on-white-background-vector-illustration-176602316.jpg"}
}
甚至只是字符串数组:
pictures = new string[]
{
"http://www.nichepursuits.com/wp-content/uploads/2014/02/buy-websites.jpg",
"http://thumb9.shutterstock.com/display_pic_with_logo/639229/176602316/stock-vector-best-buy-rubber-stamp-red-icon-isolated-on-white-background-vector-illustration-176602316.jpg"
}
第二种选择:
pictures=[{“Source”:“Value”},{“Source”:Value2}]
不是一个有效的行,不允许您用C#写这个。描述“不工作”。你有错误吗?它怎么不能实现你想要的?嗨,梅森。我已经编辑了这个主题。谢谢。你说它现在抛出一个编译错误,但是你需要解释编译错误是什么。在第一个代码块上,pictures
加倍:pictures=new{pictures=new[].
。请尝试一下pictures=new[].
谢谢。解决方法如下。