Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Exsight · Nov 11, 2014 at 01:45 PM · jsonparsing

Using SimpleJson included with UnitySocketIO-WebSocketSharp

I'm currently using UnitySocketIO-WebSocketSharp to send Json datas from server to my Unity clients through SocketIO. Socket stuff is working fine and I receive message every half seconds in JSON format but I can't process received datas easily.

I'm new to Json with unity and I would like to use the implementation included with UnitySocketIO-WebSocketSharp but I could only get my Json data as string and I didn't find any function to retrieve values from a key or a way to get Json object as an array.

I can only do this with received datas:

datas.Json.ToJsonString();

Long strings are a pain to deal with using String.Split() and String.Contains()... Did someone ever work with this version of SimpleJson and can write an example to parse my datas and retrieve key/value pairs ?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Landern · Nov 11, 2014 at 01:52 PM

This library which is NOT the same as @Bunny83 (found here) version. The key look up is done through the indexer which you can find on line:153/235. If you use anything that would make the object default out as a string(.ToString() method call for instance), it will serialize the json object as a string(see line:343).

So, say you have constructed/instantiated a SimpleJson object called sj and you want the user name(Key "UserName").

 string user = sj["UserName"]; // Thats it.

There is also a TryGetValue(line:217).

 string userName = string.Empty;
 
 sj.TryGetValue("UserName", out userName);


Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Exsight · Nov 12, 2014 at 09:50 AM 0
Share

Ok so it seems SimpleJson is a static class I cannot instanciate and the object I get is a JsonEncodedEvent$$anonymous$$essage obtain from I$$anonymous$$essage interface with data.Json, that have the ToJsonString() method.

I see static function DeserializeObject(string json) that return an object but I just want something to find value from key.

I also try something like this but it leads to unresolved error with "data" object

 IEnumerable argsList = data.Json.GetArgsAs<string>();

Can you show me how to instanciate a SimpleJson instance as you suggest ?

avatar image
0

Answer by NivekJump · Nov 11, 2014 at 02:26 PM

Hi!! This script its very usefull if you want to manipulate JSON in all the posibbles ways. http://wiki.unity3d.com/index.php?title=JSONObject

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Exsight · Nov 13, 2014 at 09:32 AM 0
Share

Thanks for the link but how can I make a JSONObject from my JsonEncodedEvent$$anonymous$$essage data ? Does it can be created from a json string ?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Deserialize nested Json data 1 Answer

CS8025 error 1 Answer

JSONUtility creates a null object of subclass even when no data 2 Answers

Parsing Facebook graph JSON 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges