You know those great ideas that come up at the spur of the moment? They just go in here.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
codestash/jsonparser_pseudo

26 lines
1.1 KiB

originalString is a string containing all the data from a JSON file ready to be parsed.
Define ReadJSON(originalString):
Iterate through al l characters of originalString as index i:
First find '{', this is the opening brace for any given JSON object.
Allocate memory for our new JSONDocument object. Set pointer to result
Read characters until a '"' is found. This is the start of a key.
Find the next '"' that is not preceded by '\' (escape characters should ignore the next character). This is the end of a key.
Store the key name in a variable called key without the quotation marks.
Next find the colon ':' character.
Now read until a non-whitespace character (ignore \t, ' ', and \n) is found.
If it's a { then we found another JSON object:
Set start to i.
Set a nesting counter to 0.
Iterate through all characters of originalString continuing from index i as index i:
As we search, if we find a '{':
Increment nesting by 1.
As we search, if we find a '}':
If nesting == 0:
Call ReadJSON( originalString.substr(start, i) )
else:
Decrement nesting by 1.