Web: Trying to import JSON into Dict with the Tutorial from the Xojo Blog

I try to import a JSON into a WebApp.

Therefore I found a tutorial in the Xojo Blog:
http://blog.xojo.com/2015/04/16/newframeworkjson/

I made a TextArea and a Button.

In the TextArea I put the example from the blog:

{ "Seagulls": { "players": { "Bob":{ "position":"1B" }, "Tom":{ "position":"2B" } } }, "Pigeons": { "players": { "Bill":{ "position":"1B" }, "Tim":{ "position":"2B" } } }, "Crows": { "players": { "Ben":{ "position":"1B" }, "Ty":{ "position":"2B" } } } }

I gave the button this action:

Dim league As Dictionary = Xojo.Data.ParseJSON(TestJSONArea.Text.ToText)

By running the app and pressing the Button I get a ugly crash with the error:

Exception: IllegalCastException
league: nil

I’m using the newst Xojo 2015.4

Is there an error in the blog, or do I something wrong?

I just did this exactly without issue. I think the problem is that you are trying to cast this to the classic framework Dictionary instead of the new framework Dictionary. (Remember, those docs are written around iOS where the new framework is the only one available.)

Try this:

Dim league As Xojo.Core.Dictionary = Xojo.Data.ParseJSON(TestJSONArea.Text.ToText)

Yes, that was my mistake. I thought I can use the new framework with Xojo Web. Because its looks so easy and cool.

Ok, I have to use the old way. :frowning:

Thank you.

There might be a miscommunication. You can use the new framework with Web, you just have to be explicit about it.

Hmmmm, the old version did have a problem, too with the tutorial in the blog:

When I use this:

[code]Dim teamName, playerName As String
Dim team, players, player As JSONItem

For i As Integer = 0 To league.Count-1
teamName = league.Name(i)
team = league.Value(teamName)
OutputArea.AppendText(teamName)
OutputArea.AppendText(EndOfLine)
players = team.Value(“players”)
For p As Integer = 0 To players.Count-1
playerName = players.Name§
player = players.Value(playerName)
OutputArea.AppendText(" " + playerName + " ")
For a As Integer = 0 To player.Count-1
OutputArea.AppendText(player.Value(player.Name(a)) + " ")
Next
OutputArea.AppendText(EndOfLine)
Next
Next[/code]

The compiler says in the line:
teamName = league.Name(i)

Type xojo.Core.Dictionary has no member “Name”

OK, now I got it: I have to change all Dictionarys to Xojo.Core.Dictionary - than it works. thanks.

Or, add “Using Xojo. Core” once, at the beginning of your code