[英]How to convert json array to C# object array
i need a help, 我需要帮助
i try to convert Json array to C# object array, here is my json 我尝试将Json数组转换为C#对象数组,这是我的json
{"jsonString":"{\"MemberSeletedId\":[358753,358754]}"}
and this is my c# object class : 这是我的C#对象类:
public class BOMemberSeletedId
{
public int MemberSeletedId { get; set; }
}
how i get a memberselectedid (array) inside json to c# array 我如何在json内将memberselectedid(array)转换为C#数组
here is my convert method at c# 这是我在C#的convert方法
public string convert(string jsonString)
{
JavaScriptSerializer js = new JavaScriptSerializer();
List<BOMemberSeletedId> param = js.Deserialize<List<BOMemberSeletedId>>(jsonString);
return param;
}
i had tried the solution inside : 我已经尝试过里面的解决方案:
Convert json to a C# array? 将json转换为C#数组吗?
but still not solve my problem 但仍然不能解决我的问题
can some one help ? 有人可以帮忙吗?
thanks 谢谢
Your property is declared as a single int
- despite it being an array in the JSON. 您的属性被声明为单个
int
,尽管它是JSON中的数组。 It looks like you should be deserializing the JSON to a single BOMembint[erSelectedID
, but the MemberSeletedId
property should be an int[]
or List<int>
: 看起来您应该将JSON反序列化为单个
BOMembint[erSelectedID
,但是MemberSeletedId
属性应该是int[]
或List<int>
:
public class BOMemberSeletedId
{
public List<int> MemberSeletedId { get; set; }
}
BOMemberSeletedId param = js.Deserialize<BOMemberSeletedId>(jsonString);
List<int> values = param.MemberSeletedId;
...
(You won't be able to return this directly from your method if your method is declared to return a string
, of course...) (当然,如果您的方法被声明为返回
string
,则将无法直接从方法中返回此值。)
(I'm assuming that jsonString
is just {"MemberSeletedId":[358753,358754]}
by this point.) (我现在假设
jsonString
只是{"MemberSeletedId":[358753,358754]}
。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.