This is a follow-up to "Json String Parsing" "Json String Parsing"
This is a follow-up to "Json String Parsing"
This is a follow-up to "Json String Parsing"
Improved version of code based state machine, based on guidance from Tersosauros,
status = READY
result={}
READY_SM = {""":STRING, ":":COLON, ",":COMMA}
NUMBER="0123456789."
for c in str1:
if state == READY:
if c in NOP:
continue
elif c in NUMBERS:
state = NUMBER
elif c in READY_SM.keys():
state = READY_SM[c]
if state == COLON:
tempKey = temp
temp = ""
statue = READY
if state == COMMA:
result[tempKey]=temp
temp=""
state=READY
if state == STRING:
if c == '""':
state = READY
else:
temp += c
if state == NUMBER:
if c == ','
result[tempKey]=temp
temp=""
state=READY
elif c in NOP:
continue
else:
temp += c
return result
Improved version of code based state machine, based on guidance from Tersosauros,
status = READY
result={}
READY_SM = {""":STRING, ":":COLON, ",":COMMA}
NUMBER="0123456789."
for c in str1:
if state == READY:
if c in NOP:
continue
elif c in NUMBERS:
state = NUMBER
elif c in READY_SM.keys():
state = READY_SM[c]
if state == COLON:
tempKey = temp
temp = ""
statue = READY
if state == COMMA:
result[tempKey]=temp
temp=""
state=READY
if state == STRING:
if c == '""':
state = READY
else:
temp += c
if state == NUMBER:
if c == ','
result[tempKey]=temp
temp=""
state=READY
elif c in NOP:
continue
else:
temp += c
return result
Improved version of code based state machine, based on guidance from Tersosauros,
Improved version of code based state machine,
Improved version of code based state machine, based on guidance from Tersosauros,
- 25.5k
- 7
- 59
- 141