简体   繁体   中英

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

{"jsonString":"{\"MemberSeletedId\":[358753,358754]}"}

and this is my c# object class :

public class BOMemberSeletedId
{
    public int MemberSeletedId { get; set; }
}

how i get a memberselectedid (array) inside json to c# array

here is my convert method at c#

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?

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. 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> :

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...)

(I'm assuming that jsonString is just {"MemberSeletedId":[358753,358754]} by this point.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM