wwDotNetBridge::ToJson
Creates a JSON string from a .NET object or value passed in.
o.ToJson(loDotnetObject)
JSON string or null on failure
Parameters
loDotnetObject
A .NET Interop object or simple value like string, number, date, bool...
llFormatted
If .T. forces the JSON to be pretty formatted
Remarks
Only works with .NET Interop objects and simple values (strings, numbers, dates, bools) - FoxPro or other non-.NET COM objects passed in will render empty objects.
Depends on NewtonSoft.Json.dll library present in addition to wwdotnetbridge.dll
Works only in the Commercial versions of wwDotnetBridge (West Wind tools)
Example
foxpro
foxpro
loCust = loBridge.CreateInstance("Westwind.WebConnection.TestCustomer")
loCust.Name = "Rick"
loCust.Company = "Westwind"
loCust.Number = 100.21
loCust.Entered = DATETIME()
loCust.Address.Street = "32 Kaiea"
loCust.Address.City = "Paia"
*** Serialize to JSON string
lcJson = loBridge.ToJson(loCust,.t.)
? lcJson
*** Deserialize into a new object entirely
loCust2 = loBridge.FromJson(lcJson,"Westwind.WebConnection.TestCustomer")
? loCust2.Company
? loCust2.Address.City
javascript
javascript
// JSON result
{
"Name": "Rick",
"Company": "Westwind",
"Entered": "2013-01-21T13:52:32",
"Number": 100.21,
"Address": {
"Street": "32 Kaiea",
"City": "Paia"
}
}
See also
Class wwDotNetBridgewwJsonSerializer::FromJson
wwJsonSerializer::ToXml
© West Wind Technologies, 2025 • Updated: 2025-03-12
Comment or report problem with topic