I guess I'm not sure why this wouldn't work assuming you have all the assemblies in place... .NET 4 is fine and that should definitely work.You need:
wwipstuff.dll
wwdotnetbridge.dll
newtonsoft.json.dll
If you downloaded the latest version (after the update I mentioned) then:
DO wwJsonSerializerDO wwDotnetBridge
loSer = CREATEOBJECT("wwJsonSerializer")
loPerson = loSer.DeserializeJson([{ name: "Rick", company: "West Wind" }])
? loSer.cErrorMsg
? loPerson.Name
? loPerson.Company
Note: DeserializeJson() will deserialize the above - Deserialize won't because technically that's not valid JSON (identifiers need to be quoted) which is one of the reasons DeserializeJson() is preferrable.
Deserialize basically works with terse JSON as generated by the Serialize() method and by that created from browser based JSON parsers. If the formatting varies any - Deserialize() likely fails. DeserializeJson() should handle it all though.
Best way to check if everything works as intended, is that run the above code in the wwclient install folder. Set a shortcut to VFP.exe with a start folder in wwClient, then run the above code. This will ensure everything is in the right place with paths for the support libs etc. set and the dlls in the root folder.
+++ Rick ---
Well, I'm getting along OK with standard deserialize json. The web developer is making sure, call by call, that what he sends works.
Still wish I could have gotten this to work. I did see the reference to .NET before posting my problem. Is having .NET 4.0 too high of a release?
Roger,
DeserializeJson() works although there's a bug with top-level arrays that needed fixing (which has been updated). If you look in the documentation, it mentions that you need to have .NET 2.0 or later installed in order to use it as it uses a .NET component to handle the deserialization. Please check the documentation for more information.
Deserialize() uses wwRegEx to handle the manual deserialization code. wwRegEx.prg is in the classes folder and you just have to SET PROCEDURE to it. Nothing has changed in this regard - it wasn't auto-included before either...
I've added it now (as it should be). You can re-download wwClient.zip with the same registration info which includes the updated wwJsonSerializer class as well as an updated wwIPstuff.dll that has the right version number (nothing else changed).
+++ Rick ---
I'm really sorry to be such a pain about this. But, all of the chasing around I've been doing to get DeserializeJson to work has caused Deserialize (which I had working) to now fail. Yesterday you helped me get Deserialize to work on a very simpe code example. After that, I had good success with Deserialize in the code I'm building. Now, Deserialize fails in the very last statement from the code from wwutils shown below. The error is that wwRegEx.prg does not exist.
* wwUtils :: GetRegexObject
************************************************************************
* wwUtils :: GetwwRegexObject
****************************************
*** Function:
*** Assume:
*** Pass:
*** Return:
************************************************************************
FUNCTION GetwwRegexObject()
IF VARTYPE(__WWREGEX) != "O"
PUBLIC __WWREGEX
LOCAL lcRegEx
lcRegEx = "wwRegEx.prg"
__WWREGEX = NEWOBJECT("wwRegEx",lcRegEx)
What's the error?
If the Init() fails, then again it's most likely the missing wwipstuff.dll or wwdotnetbridge.dll in your FoxPro path. Both DLLs are best if they are in the current path.
+++ Rick ---
The code below still fails in DserializeJson
DO wwJsonSerializer && Load libs
DO wwDotnetBridge
loJson = CREATEOBJECT("wwJsonSerializer")
lcJson = '["Value,1","Value2. This \"is\" neat","Value3"]'
loResult =loJson.DeserializeJson(lcJson)
The failuer happens within "Init" in wwdotnetbridge with this IF statement.
*** Fail creation if the object couldn't be created
IF ISNULL(this.Load())
ERROR "Unable to load wwDotNetBridge: " + this.cErrorMsg
RETURN .F.
ENDIF
No. wwDotnetBridge does not get loaded by default.
But doing:
DO wwJsonSerializerDO wwDotnetBridge
somewhere to load the libraries is required.
+++ Rick ---
I see DeserializeJson() in the latest wwJsonSerializer.prg, but not in wwDotnetBridge.prg (dated Feb 3 in the zip file I downloaded yesterday).
After recompiling everything I could think of, I'm getting a different error - file GetwwDotnetBridge.prg does not exist. I see this is in wwDotNetBridge.prg. Shouldn't these routines be available by my starting up with "DO WWCLIENT"?
Make sure you recompile all of your files. Look in the help file for updating to the latest version or updating from the shareware version.
DeserializeJson() should be there ( you can double check the wwDotnetBridge.prg source file)...
+++ Rick ---
Yes, I am a registered user and downloaded all of the latest upates yesterday. I'm looking at the Help and trying to determine what needs to be loaded in advance of me calling DeserializeJson. I have the latest WCONNECT.H (file date Feb 3) in my base development folder and "DO wwclient" runs at when I start up in development.
... and only the very latest version that was released a couple of days ago. The shareware version has not been updated yet - it's only in the registered version at this point.
+++ Rick ---
I have the very latest wwIpstuff.dll, wwDotnetBridge.dll and NewtonSoft.Json.dll in the same folder as where I'm doing my development. However, the code below returns the error "Property DESERIALIZEJSON is not found". Can you let me know what I could be missing?
DO wwJsonSerializer && Load libs
loJson = CREATEOBJECT("wwJsonSerializer")
lcJson = '["Value,1","Value2. This \"is\" neat","Value3"]'
loResult =loJson.DeserializeJson(lcJson)
![]()