0

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

Community
  • 1
  • 1
Hansen
  • 650
  • 1
  • 11
  • 32
  • 1
    It appears you have JSON inside a string in that is inside some JSON. You'll need to retrieve that string from the outer JSON and then parse/deserialise the inner JSON. – Richard Apr 07 '15 at 09:35

1 Answers1

2

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

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194