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
1
Question by deathmtn · Jan 24, 2012 at 10:07 PM · jsonlibrarywebservicerest

RESTful libraries for Unity

What is the simplest way to interact with a RESTful web service that deals in JSON? I see that WWWForm will let me GET and POST to a web service and that I could use litJSON to encode and parse my data, but litJSON doesn't seem to have been maintained in a while.

How do Unity developers usually do this? Is there a Unity analogue of Resty for Objective-C?

Comment
Add comment · Show 3
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 BeHappy · Sep 17, 2012 at 07:34 AM 0
Share

anyone has an answer for this ??

avatar image amostajo · Oct 21, 2013 at 10:22 PM 0
Share

I'm still looking for HTTP classes... in terms of Json, SimpleJSON (http://wiki.unity3d.com/index.php/SimpleJSON) worked for me.

avatar image Benproductions1 · Oct 21, 2013 at 10:48 PM 0
Share

I usually use WWW for all HTTP services

6 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Deepscorn · Feb 22, 2017 at 08:55 PM

Update: Now, it's better to use unity's UnityWebRequest for requests. For simple serialization you can use unity's JsonUtility. Though, if you want incapsulation, you may want accessors (public get, private set). Then you can choose something from the web. There are plenty of serializers. Newtonsoft Json and https://github.com/neuecc/Utf8Json can do. Not tried them though, still have to maintain legacy codebase with legacy simplejson serializer.

Below is my original answer, written in 2017:

I am using RestSharp with success for android, iOs, Windows, Mac OS platforms. There is a fork of RestSharp which fixes some issues so that RestSharp works for Unity https://github.com/eamonwoortman/RestSharp.Unity. It's cool because you can use DesirializeAs attibute and use any names for fields, even with spaces. Example:

 public class PurchasedProductResponse
         {
             [DeserializeAs(Name = "product id")]
             public string ProductId { get; set; }
 
             [DeserializeAs(Name = "rewards")]
             public List<MoneyPrizeResponse> MoneyPrizes { get; set; }
         }
 
     public class MoneyPrizeResponse
     {
         [DeserializeAs(Name = "bonusData.imageUrl")]
         public string ImageUrl { get; set; }
     }



Comment
Add comment · Show 3 · 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 Deepscorn · Feb 22, 2017 at 08:56 PM 0
Share

It's cool, Unity added JsonUtility to work with jsons, but it still lacks such feature

avatar image Deepscorn · Dec 12, 2017 at 03:35 PM 0
Share

Also, I used SimpleJson. It's for serializing/deserializing only. It also supports aliasing via DataContract (enables through SI$$anonymous$$PLE_JSON_DATACONTRACT define). https://github.com/facebook-csharp-sdk/simple-json/blob/master/src/SimpleJson/SimpleJson.cs

avatar image misher · Mar 08, 2019 at 10:56 AM 0
Share

Yea, there is a client generator, the problem is that it doesn't work in WebGL and has several other limitations. Please take a look at https://github.com/kolodi/UnityOpenApi - Unity friendly restful API client generator.

avatar image
1

Answer by fedor.shubin · Jan 28, 2015 at 03:05 PM

We've created our REST SDK on the shoulders of UnityHTTP. It provides API similar to restangular, implements path building, error handling, and other useful things. You can find it here: https://github.com/vedi/restifizer-unity3d

For example it allows something like that:

 RestifizerManager.ResourceAt("api/users").
   WithBearerAuth().
   One(userId).
   Patch(parameters, (response) => {
     // response.Resource - at this point you can use the result 
   });
 

 
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 adam-aurea · Jan 02, 2017 at 12:56 PM 1
Share

What is important to note is that it depends on https://github.com/andyburke/UnityHTTP which uses the GPL license, which means when you distribute your Unity application you must make the source code public.

avatar image
1

Answer by misher · Mar 08, 2019 at 10:54 AM

I've been working on Unity-specific Restful API client generator https://github.com/kolodi/UnityOpenApi, it's based on Swagger/OpenAPI standard and use convenient Unity tools and approaches.

Comment
Add comment · 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
0

Answer by raybarrera · Oct 21, 2013 at 10:52 PM

I've used JsonFx, which has worked great. Get it here

As for talking to the web service, you could go with WWW, but be ware that it does not support headers for GET requests. You could write your own solution using sockets, or do what I did and grab uniweb. Hope that helps.

Comment
Add comment · 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
0

Answer by jimunwin · Aug 20, 2014 at 05:31 AM

I've been using UnityHTTP, which has been super simple to set up and gives me the "PUT" verb, though it hasn't been without its problems. Your code ends up looking something like this:

 HTTP.Request theRequest = new HTTP.Request( "PUT", myUrl, lightSettings ); // build the request
 theRequest.Send(); // send the request

Where "myUrl" is a string and "lightSettings" is a hashtable.

Comment
Add comment · 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
  • 1
  • 2
  • ›

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

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I cant get response json from rest call in Unity 1 Answer

JSON-Serializer (Renewed open) 0 Answers

Set Content-Length header for UnityWebRequest POST requests in 2017.3? 1 Answer

How to run a human avatar from json response from webservice? 1 Answer

Create a glossary using Simple JSON, loading data dynamically 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