0

i have the following json string from an http post:

Dim json As String = "{" + """contacts"":" + "[{" + """name"":""jocelyne" + """," + """mo"":""jocelyne" + """}" + ",{" + """name"":""eliane" + """," + """mo"":""12345678" + """}" + "]}"

how can i deserializa this json array? i tried using dictionary but it did not work note that the length of the json array may be very big

 Dim jss As New System.Web.Script.Serialization.JavaScriptSerializer()
 Dim dict As Dictionary(Of String, String) = jss.Deserialize(Of Dictionary(Of String, String))(json)
 For Each item As KeyValuePair(Of String, String) In dict
        Response.Write(item.Key & " - " & item.Value & "<br>")
    Next
martineau
  • 119,623
  • 25
  • 170
  • 301
User7291
  • 1,095
  • 3
  • 29
  • 71
  • Maybe better idea to deserialize it to custom object? http://stackoverflow.com/questions/9586585/convert-json-to-a-c-sharp-array – Mike Oct 17 '13 at 11:40

3 Answers3

0

Try using JSON.Net

  Dictionary<string,string> deserializedProduct =
    JsonConvert.DeserializeObject<Dictionary<string,string>>(json);
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120
  • i tried what you suggested but i got this error: `Error reading string. Unexpected token: StartArray. Path 'contacts', line 1, position 13.` do you have any idea how to fix it? – User7291 Oct 17 '13 at 11:44
  • @JocelyneElKhoury, then there could be error in JSON format. please check – Murali Murugesan Oct 17 '13 at 11:47
  • i keep getting there is no source code available for the current location although i added the reference to my project and it's in the bin file .. – User7291 Oct 22 '13 at 12:02
  • can you please check for me the following question: stackoverflow.com/questions/19535504/… – User7291 Oct 23 '13 at 08:00
0

Try this, this is C# code

dynamic obj = JsonConvert.DeserializeObject(json);
var contacts = obj["contacts"];
Amit
  • 15,217
  • 8
  • 46
  • 68
0

try this

   System.Web.Script.Serialization.JavaScriptSerializer ss1 = new System.Web.Script.Serialization.JavaScriptSerializer();
Dictionary<string, string> dicobj = new Dictionary<string, string>();
        dicobj = ss1.DeserializeObject(JsonString) as Dictionary<string, string>;
Aravind
  • 1,521
  • 2
  • 12
  • 23