Loading ...
Sorry, an error occurred while loading the content.

RE: [json] parser assistance

Expand Messages
  • Atif Aziz
    Perhaps it may help to look at the JSON parsing bits (written in C#) that are part of the Jayrock[1] project. I originally started with the C# code from
    Message 1 of 3 , Dec 16, 2005
    • 0 Attachment
      Perhaps it may help to look at the JSON parsing bits (written in C#)
      that are part of the Jayrock[1] project. I originally started with the
      C# code from json.org[2] (which I believe was a straight port of the
      Java version) but then re-factored it so that the output of the parser
      was more of an AST (Abstract Syntax Tree). You want to start by checking
      out two files, namely JsonParser.cs and IParserOutput.cs. The JsonParser
      class contains just the parsing code, but the parser itself does not
      mandate a particular class of output (put another way, a particular
      graph of objects and their types). It leaves that up to the
      IParserOutput implementation that's handed to it. So what JsonParser
      essentially does is that it recognizes the various elements of JSON in
      the string being parsed and then calls back the corresponding properties
      or method(s) of IParserOutput to build/yield the desired representation
      for output. The benefit of this approach is of course that the parsing
      code does not change with your transformation strategy (that is, how you
      decode JSON into an object graph or document).

      So here's what I would suggest. Start by porting the IParserOutput
      interface to Visual Basic, which should be straight forward (hint: you
      can essentially use the Variant data type wherever you see object being
      used). Next, create an implementation of this interface that simply
      outputs debug messages in each call. Finally, port over the JsonParser
      code. This will get most of your headaches out of the way. As a test
      supply the diagnostic IParserOutput implementation to JsonParser and see
      if the right messages get pumped out to the debug window for a give JSON
      string. If all goes well, the real work left will be writing a proper
      IParserOutput implementation that yields the VB data types and I assume
      that's where you want to get and spend most of your brains.

      -- Atif

      [1] http://jayrock/berlios.de/
      [2] http://www.crockford.com/JSON/cs

      -----Original Message-----
      From: json@yahoogroups.com [mailto:json@yahoogroups.com] On Behalf Of
      MPCM
      Sent: Friday, December 16, 2005 3:46 PM
      To: json@yahoogroups.com
      Subject: [json] parser assistance

      I have been using JSON in several web projects via javascript and PHP,
      it is truly a great format and lets us developers focus on apps. I am
      trying write a parser for JSON, at least to handle the data formats in
      basic, specifically visual basic. Doing a json encode routine is
      fairly straight forward (ignoring the fact that vb data types for
      named arrays (objects) is less than ideal).

      I've looked over the code in other languages, and I am looking for
      some guidance from someone a smarter than me in this. I understand the
      basics of parsing/tokenizing, and the lack of an included regexp
      ability in vb6 makes this difficult. My goal is to have a vb6 working
      parser without external dll/references. including a script engine is
      also not really an option, again the goal is for a raw vb6 parser.

      The way I was looking at this was to read it char by char and, as it
      detected each possible data type/set/nest, strip out the inferred
      closing chars on the end, and pass that sub string and a current
      position in the existing object to the same routine, letting it
      recursively call itself to do the parsing.

      Every time I have headed down this path, it starts to get somewhat
      complex, and I keep feeling like I am doing this the `wrong` way, the
      code just seems like too much of a hack. Any suggests insight, code,
      or pseudo code covering concepts on dealing with this would be much
      appreciated.

      --
      Matt




      Yahoo! Groups Links
    Your message has been successfully submitted and would be delivered to recipients shortly.