Link to home
Start Free TrialLog in
Avatar of pamela rizk
pamela rizkFlag for Lebanon

asked on

asp Json

dear all

please i need help i am stuck for three days

 Dim sJSON1 As String = "{'ConditionParameter' : {'DocType':'6', 'Reference_Num':'573942', 'StkMethod':'LOAD_H' }}"
no problem when using the below command :
dim ArrayList = new ArrayList
 For Each Dict As KeyValuePair(Of String, Object) In mydictionnary 'ex :ID1, arraylist
            Array_List.Add(TryCast(Dict.Value, ArrayList))
        Next

Array_List(0) is not nothing

but

Dim sJSON1 As String = "{'ConditionParameter' : [{'DocType':'6', 'Reference_Num':'573942', 'StkMethod':'LOAD_H' }]}"
no problem when using the below command :
dim ArrayList = new ArrayList
 For Each Dict As KeyValuePair(Of String, Object) In mydictionnary 'ex :ID1, arraylist
            Array_List.Add(TryCast(Dict.Value, ArrayList))
        Next

Array_List is nothing

so in brief if no "[" in the json i have an error please help asap.
Avatar of ste5an
ste5an
Flag of Germany image

Your code is incomplete, thus it makes no sense:

You've defined sJSON1, but you don't use it at all. What does mydictionnary contain? Who does it declaration look like? Why transforming it into an ArrayList?
Avatar of pamela rizk

ASKER

what i am trying to say is that i have ajson

Dim sJSON1 As String = "{'ConditionParameter' : [{'DocType':'6', 'Reference_Num':'573942', 'StkMethod':'LOAD_H' }]}"
i need to deserialize it intoa  dataset how to do i??
sorry to say but still now working please helpp
please help since i am stuck
E.g. using Newtonsoft.Json (use nuget to install that pakage):

 
Imports Newtonsoft.Json

Module Module1

    Sub Main()

        Dim jsonString As String = "{'ConditionParameter' : [{'DocType':'6', 'Reference_Num':'573942', 'StkMethod':'LOAD_H' }]}"
        Dim parameters As DataSet = JsonConvert.DeserializeObject(Of DataSet)(jsonString)
        Dim parametersTable As DataTable = parameters.Tables("ConditionParameter")

        Console.WriteLine(parametersTable.Rows.Count)

        For Each row As DataRow In ParametersTable.Rows
            Console.WriteLine(row("DocType") + " - " + row("Reference_Num") + " - " + row("StkMethod"))
        Next row

        Console.WriteLine("Done.")
        Console.ReadLine()

    End Sub

End Module

Open in new window

is there any alternative for newtonsoft?
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial