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

1
  • 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. Commented Apr 7, 2015 at 9:35

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.