json.ToString Not Returning a String

This question pertains to an application running on a raspberrypi.

When I try to use a URL connection as follows:

Window1.URLConnection1.SetRequestContent( json.ToString,  "application/json")

I get an error suggesting that json.ToString is not returning a string:

Module1.SaveToCellarLog, line 112
There is more than one method with this name but this does not match any of the available signatures.
Window1.URLConnection1.SetRequestContent( json.ToString,  "application/json")

Module1.SaveToCellarLog, line 112
Parameter "content" expects type String, but this is type Int32.
Window1.URLConnection1.SetRequestContent( json.ToString,  "application/json")

The json was generated using:

Dim json As New Chilkat.JsonObject

Should I be generating the json object using some other approach?

I have never used Chilkat, but from the error message my guess is their JsonObject does not have a .ToString method or property. The native Xojo JSON object does, but you are creating a Chilkat object so perhaps they call their method something different. I’d suggest checking the Chilkat docs for available properties or methods. I’m gunessing it does not include ToString. So either change to their equivalent, or setup your own extension to their object which adds a ToString method but returns whatever they call it.

@Matthew_Cottrell - Where is your code where you are loading the Chilkat.JSON object?

Quick Example that should get you there.

Var jsonTestStr as String =  "{""Result"": ""OK"",""Reports"": [{""ReportTxt"": ["" "",""REPORT GROUP: DAILY REPORT""]}]}"
Dim json As New Chilkat.JsonObject
Var success as Boolean = json.Load(jsonTestStr)
json.EmitCompact = False

Var jsonOutputStr as String = json.Emit()

Window1.URLConnection1.SetRequestContent( jsonOutputStr,  "application/json")

The above code you are trying is for Xojo’s JsonItem object (Json.ToString)

@Douglas_Handy was spot on as with Chilkat you need to use Chilkat.Json.Emit() to return the JSON String (pretty version)


Using Emit() solved this issue for me.

1 Like