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

Jon Skeet
people
quotationmark

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

people

See more on this question at Stackoverflow