Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3755

Parsing JSON text

$
0
0

I have been trying to parse a large JSON text file. This file has several layers of dictionary entries and their values. I have looked at other posts, and the examples and I am able to retrieve the first layer dictionary and its values, but I don’t know how to drill down to the other dictionary layers and their values. I am also trying to determine the number of layers / dictionaries in each of the sub categories (?).

My code is below, and the results can be shown the attached pics.

`
Dim spTics, nsdqTics, aFY_END, Cash_Flow, FY_END as String
Dim TIS as TextInputStream
Dim SpJsonFIle as FolderItem = GetFolderItem("aapl.json")

Dim SPText as Text
Dim res as Dictionary
Var  tname as JSONItem

Try
  TIS=TextInputStream.Open(SpJsonFile)
  SPText=TIS.ReadAll.toText
  'SPText=spTics.totext
Catch err 
  'MessageBox(err)
  Return
End Try

Try
  res=ParseJSON(SPText)
Catch Err 
  'MessageBox(Err)
  Return
End Try

var jsSource as new JSONItem(res)
var tItems() as String
tItems() = jsSource.Keys
var i as integer
i=tItems.Count

break`

Contents of res variable:

contents of Financials (item in res):

and it continues with nested dictionaries form there…

How do I read the number / names of the dictionaries after the initial read (res), and then retrieve the values from those dictionaries?

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 3755

Trending Articles