|
top
|
Subject: JSON problem Author: (Deleted User) Date: 09 Oct 2011 04:54 AM
|
>Ian,
>
>Have you looked at the .net
>built-in JSON
>serialize/deserialize feature?
>
>
>http://msdn.microsoft.com/en-u
>s/library/system.runtime.seria
>lization.json.datacontractjson
>serializer.aspx
Ivan
Yes, in the past 1-2 years I have been using the JSON serialize/deserialise w/o the data contract facility, and it is quite forgiving in that the [ ] enclosing some JSON files is permitted. Then, using regex, it is reasonably simple to process and use arrays or dictionaries (in .NET) to handle the slightly more complex parts.
Also useful is JSON.NET, written by James Newton-King. I used his JSON to XML method (a tiny part of his library).
However, once the schema has been established (and assuming it remains constant) I have found that generated classes are very flexible and powerful for the processing and representation I need to perform.
Initially, the generation of .NET code classes is a little circuitous, particularly if the tokens used by the designers/authors of the JSON data structures are uninformative - eg, "a", "b", ... "f" { "a" "b" "d" "f" ... "s"} - ie, "f" is an array that includes elements "f".
For some years, Microsoft has provided a utility (xsd.exe) with versions of the Windows SDK (free to download), and provided that the JSON can be converted to XML that small command-line utility can generate an XSD, and from that file xsd.exe can produce code classes in VB.NET or C#. The latest couple of versions of xsd.exe do a good job with the code generation, and with some manipulation and supplementary code I have been able to make some good progress.
Once that is done, JSON.NET and other tools are not needed.
Stylus Studio doesn't really play a part in this process, for me - except, of course, for your reminder that I had no root element in the imported JSON (and after I had removed the [] from those files).
I haven't looked at the XML Importer tools with SS, but it's possible that the [ ] could be removed and replaced with a root element in the XML (which is essentially what it represents, to my understanding); and that SS could be used to make JSON/XML files like the one I gave as an example a lot more readable (so the "f" {... "f"} complication does not take so long to untangle in generated C# code classes); and I assume SS could call xsd.exe to generate these classes, too.
On reading over the above, I think that this may be a bit confusing w/o seeing the 2 groups of JSON files I have been dealing with.
Ian Thomas
--------------
Stylus Studio 2011 XML Enterprise Suite R2 (Build 1756a)
|
|
|
|