You are trying to pass an incompatible data type to your method: in your caller method your dictionary is of type string, string
and your function awaits dictionary of type string, object
. You have two solutions:
- either change the signature of your dictionary in the main part to
Dim data As New Dictionary(Of String, Object)
- or change the signature to the dictionary parameter of the method to
ByVal data As Dictionary(Of String, String)
A possible solution looks like this:
Public Shared Function Create(ByVal data As Dictionary(Of String, String)) As [String]
' Serializes the body into JSON using the fastJSON library.
Dim json As String = Newtonsoft.Json.JsonConvert.SerializeObject(data)
return json
end function
The call:
Dim data As New Dictionary(Of String, String)
data.Add("customer", "TEST")
data.Add("secretKeyId", "2222222222222")
data.Add("secretKey", "333333333333333")
Dim dataAsJson = Create(data)
Console.WriteLine(dataAsJson)
The output:
{"customer":"TEST","secretKeyId":"2222222222222","secretKey":"333333333333333"}
This would also work correctly in this case and create the same result as above:
Public Shared Function Create(ByVal data As Dictionary(Of String, Object)) As [String]
' Serializes the body into JSON using the fastJSON library.
Dim json As String = Newtonsoft.Json.JsonConvert.SerializeObject(data)
return json
end function
Dim data As New Dictionary(Of String, Object)
data.Add("customer", "TEST")
data.Add("secretKeyId", "2222222222222")
data.Add("secretKey", "333333333333333")
Dim dataAsJson = Create(data)
Console.WriteLine(dataAsJson)