Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Pr3ato · Mar 21, 2017 at 12:58 PM · wwwjsonserializable

JsonUtility.FromJson cannot convert object from rest call

Dear Unity,

I have a rest call which implements sensor data and creates an object from it. For some reason it won't parse my json into an object with JsonUtility.FromJson even though i have a valid json:

The error is:

     system.ArgumentException' in UnityEngineProxy.dll
    ArgumentException: JSON must represent an object type.

Which of course means that it must but a correct object type but as far as i can see it is correct.

My json which i recieve with www.downloadHandler.text would be:

  "{\"guid\":\"2a005e1e-a417-43d9-812c-4cbec6e70847\",\"deviceName\":\"Bmp280Sensor\",\"level\":\"critical\"}"

with the object :

 [System.Serializable]
 public class Bmp280  {

 public Guid guid;
 public string deviceName;
 public string level;

 }

and it's being called like this:

 private Bmp280 TextToJsonBMP280Object(string getMessage)
 {
     System.Diagnostics.Debug.WriteLine("The message is: " + getMessage);
     return JsonUtility.FromJson<Bmp280>(getMessage);
 }


Does anyone see what I am doing wrong? As far as i can see it's exactly what is requested from the function...

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by gameplay4all · Mar 21, 2017 at 01:36 PM

I think it has something to do with the backslash before every quotation mark, or is this formatting because of this forum?

The JsonUtility makes JSON that looks like this:

 {"customColor":{"r":100,"g":180,"b":120,"a":255},"myBool":true}

So no backslashes :) Hope this was your problem,

-Gameplay4all

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 Bunny83 · Mar 21, 2017 at 01:44 PM 0
Share

Yes, if the actual text contains escaped quotation marks it won't work. If it in deed contains an escaped string for some reason you have to unescape it.

avatar image Pr3ato · Mar 21, 2017 at 02:34 PM 0
Share

Wow that is probably it. Will try this tommorow and will make you both as answer if that is the answer!

avatar image Pr3ato · Mar 21, 2017 at 03:23 PM 0
Share

Ok could not resist tried it anyways.

It seems to work and it gives me the following message now: "{"guid":"78002716-cfb5-417c-9777-8bee4ee9d94a","deviceName":"Bmp280Sensor","tempSensorValue":24.2481155,"pressureSensorValue":101041.328,"altitudeSensorValue":23.64571,"measurementTime":"2017-03-21T07:53:43.9098904-07:00","measurename":"LightSensor","level":"critical"}"

Thid does bring me to the next error : JSON parse error: The document root must not follow by other values.

But i think this comes down to something else but that wouldn't fit in this topic. Thanks all :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Upload/store string to html/json script?? 0 Answers

iPhone bad URL 0 Answers

WWW data acquisition from remote server failing 2 Answers

Using MiniJSON 1 Answer

save and load json score to web/server 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