I have a console app that will be used to replace a web service API using PAW to test.
I successfully accept, parse the path and URL parameters and the get info from a database.
I use this Method ‘SelectSQLProcess’ with a return type = Dictionary. This Dictionary is sent back to PAW where the Response contains JSON info.
Var JSONItem_Array As New JSONItem("[]")
// See if there is data (RowSet) to be returned...
If Not data.AfterLastRow Then
// Loop over each row...
While Not data.AfterLastRow
// We'll treat each record as a dictionary.
Dim Record As New Dictionary
// For each column...
For i As Integer = 0 To data.LastColumnIndex
// Add the column name / value pair as a dictionary element.
Record.Value( data.ColumnAt(i).Name.DefineEncoding(Encodings.UTF8)) = data.ColumnAt(i).StringValue.DefineEncoding(Encodings.UTF8)
Next
// Add the record to the JSON object.
JSONItem_Array.Add(Record)
// Go to the next row.
data.MoveToNextRow
Wend
// Close data RowSet
data.Close
// Convert array of JSON to Dictionary
Var json As Dictionary = ParseJSON( JSONItem_Array.ToString )
// The above throws a cast error: Array cannot be cast to Dictionary
// Return Dictionary
Response = json
I have attempted several ways to convert to a Dictionary but have not been successful. Just in case here is a snippet of the JSONItem array.
[{"VRCNUM":"15354796","Last_Name":"ALASTNAME","First_Name":"AFIRSTNAME","Middle_Name":"H","Suffix":"","House_Number":"10","Street":"STREET DR","Apartment":"","Half_Address":"0","Res_Addr_Line2":"","Res_Addr_Line3":"","City":"SOMECIRTY,"State":"SOMESTATE","Zipcode":"11111","Zip4":"","Telephone":"(111)271-1423","Email_str":"","Mail_Address1":"","Mail_Address2":"","Mail_Address3":"","Mail_Address4":"","Mail_City":"","Mail_State":"","Mail_Zipcode":"","Mail_Zip4":"","Party":"DEM","Gender":"F","Date_of_Birth":"1938-11-02","L_T":"57","Election_District":"8","LD":"15","AD":"135","SD":"55","CD":"25","CC_WD_Vil":"","Town_Code":"060","Last_Update":"2012-04-29 00:00:00","Original_Reg_Date":"1960-01-01 00:00:00","Statevid":"SOMESTATE000000000023111777","Sep_14":"N","Nov_14":"Y","Sep_15":"J","Nov_15":"Y","Apr_16":"Y","Sep_16":"J","Nov_16":"Y","Sep_17":"J","Nov_17":"Y","Jun_18":"Y","Sep_18":"Y","Nov_18":"Y"},{"VRCNUM":"100538","Last_Name":"ANOTHERLASTNAME","First_Name":"ANOTHERFIRSTNAME","Middle_Name":"P","Suffix":"","House_Number":"7","Street":"ACORN DR","Apartment":"","Half_Address":"0","Res_Addr_Line2":"","Res_Addr_Line3":"","City":"SOMECITY","State":"SOMESTATE","Zipcode":"11111","Zip4":"","Telephone":"(111)889-0610","Email_str":"","Mail_Address1":"","Mail_Address2":"","Mail_Address3":"","Mail_Address4":"","Mail_City":"","Mail_State":"","Mail_Zipcode":"","Mail_Zip4":"","Party":"DEM","Gender":"F","Date_of_Birth":"1986-01-29","L_T":"57","Election_District":"8","LD":"15","AD":"135","SD":"55","CD":"25","CC_WD_Vil":"","Town_Code":"060","Last_Update":"2017-03-24 00:00:00","Original_Reg_Date":"2004-02-06 00:00:00","Statevid":"SOMESTATE000000000023783022","Sep_14":"N","Nov_14":"Y","Sep_15":"J","Nov_15":"Y","Apr_16":"Y","Sep_16":"J","Nov_16":"Y","Sep_17":"J","Nov_17":"Y","Jun_18":"Y","Sep_18":"Y","Nov_18":"Y"},{"VRCNUM":"156217","Last_Name":"LASTNAME2","First_Name":"FIRSTNAME2","Middle_Name":"G","Suffix":"","House_Number":"7","Street":"ACORN DR","Apartment":"","Half_Address":"0","Res_Addr_Line2":"","Res_Addr_Line3":"","City":"SOMECITY","State":"SOMESTATE","Zipcode":"11111","Zip4":"2601","Telephone":"","Email_str":"","Mail_Address1":"","Mail_Address2":"","Mail_Address3":"","Mail_Address4":"","Mail_City":"","Mail_State":"","Mail_Zipcode":"","Mail_Zip4":"","Party":"DEM","Gender":"M","Date_of_Birth":"1985-02-25","L_T":"57","Election_District":"8","LD":"15","AD":"135","SD":"55","CD":"25","CC_WD_Vil":"","Town_Code":"060","Last_Update":"2018-12-06 00:00:00","Original_Reg_Date":"2005-07-08 00:00:00","Statevid":"SOMESTATE000000000023379133","Sep_14":"J","Nov_14":"Y","Sep_15":"J","Nov_15":"N","Apr_16":"J","Sep_16":"N","Nov_16":"Y","Sep_17":"J","Nov_17":"N","Jun_18":"J","Sep_18":"N","Nov_18":"Y"},{"VRCNUM":"9181","Last_Name":"LASTNAME1","First_Name":"FIRSTNAME1","Middle_Name":"E","Suffix":"","House_Number":"95","Street":"ANGELS PATH","Apartment":"","Half_Address":"0","Res_Addr_Line2":"","Res_Addr_Line3":"","City":"ANOTHERCITY","State":"SOMESTATE","Zipcode":"11111","Zip4":"","Telephone":"","Email_str":"","Mail_Address1":"","Mail_Address2":"","Mail_Address3":"","Mail_Address4":"","Mail_City":"","Mail_State":"","Mail_Zipcode":"","Mail_Zip4":"","Party":"DEM","Gender":"F","Date_of_Birth":"1960-07-06","L_T":"57","Election_District":"34","LD":"15","AD":"135","SD":"55","CD":"25","CC_WD_Vil":"","Town_Code":"060","Last_Update":"2014-09-04 00:00:00","Original_Reg_Date":"2000-03-14 00:00:00","Statevid":"SOMESTATE000000000023774498","Sep_14":"N","Nov_14":"N","Sep_15":"J","Nov_15":"N","Apr_16":"Y","Sep_16":"J","Nov_16":"Y","Sep_17":"J","Nov_17":"N","Jun_18":"N","Sep_18":"N","Nov_18":"Y"}]
I include a pic of PAW with output that simulates what I am attempting to receive. I am using XOJO 2021r2.1