0

I found a tutorial for server implementation in a game on this link:

http://unity-tutorials.blogspot.in/

I implemented the code for my server sending in the following data on the Login Section to my Server:

{"email":"rudi@mrpatch.co", "pass": "mrpatch"}

This server is implementing JSON and is giving the below response :

Receive response: "{\"status\":\"success\",\"data\":[{\"id\":\"1\",\"email\":\"rudi@mrpatch.co\",\"password\":\"mrpatch\",\"first_name\":\"Rudi\",\"last_name\":\"Ullon\",\"birth_date\":\"1981-03-20\",\"status\":\"1\"}]}"

There is a JSON parser script in this project, which returns System.string , this is being used by a parser in my other script LoginService.js But while I am trying to store this in a Boo.Lang.Hash (hashtable) it gives me error in following code:

var parsed : Boo.Lang.Hash = JSONParse.JSONParse(httpResponse.text);

This is the Error message I am getting:

InvalidCastException: Cannot cast from source type to destination type.
LoginService+$sendLoginData$6+$.MoveNext () (at Assets/Scripts/StartMenu/LoginService.js:61)

I have tried saving it a Boo.Lang.Hash, as String etc. but nothing seems to be working.

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
Neutrino
  • 21
  • 7

3 Answers3

1

Oh boy...

You seem to have quite some conceptual issues with type casting and that's a far too broad topic (joke link). :P

The error message means you can't convert from String to that Hashtable through casting. You need a function to convert it for you or do it yourself.

The JSONParse you mentioned can actually do it:

var jsonData : json = json.fromString(httpResponse.text);

At least now you have jsonData.values which can be easily converted to a Hashtable...

But keep in mind "Hashtables" are obsolete and even the Unity Player will warn you about it. Read more.

Community
  • 1
  • 1
cregox
  • 17,674
  • 15
  • 85
  • 116
1

if you have json you can do in this way.

var parsed : Boo.Lang.Hash = JSONParse.JSONParse(your json );
tobias_k
  • 81,265
  • 12
  • 120
  • 179
0

you must use the JsonPare.js from source code on the demo.https://docs.google.com/file/d/0B0HipNssJJD-bEh0Wi1XeV9PSlE/edit