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 rhose87 · Jun 08, 2012 at 02:57 PM · c#jsonlitjson

Parse JSON with LitJSON

I would like to parse a JSON using LitJSON. My JSON looks like :

 {
     "title_roof": "TILESen",
     "detailsRed": "Classic red",
     "detailsRedShaded": "Shaded red",
     "detailsGreen": "Forest green",
     "detailsGreenShaded": "Shaded green",
     "detailsTerracota": "Terracotta",
     "detailsBrownShaded": "Shaded brown",
     "detailsBlack": "Black ",
     "title_wall": "WALLS",
     "wall1": {
         "name": "wall_name",
         "normal_texture": "normal.png",
         "hover_texture": "hover.png",
         "wall_texture": "texture.png"
     },
     "wall2": {
         "name": "wall_name_2",
         "normal_texture": "normal2.png",
         "hover_texture": "hover2.png",
         "wall_texture": "texture2.png"
     },
     "tile1": {
         "name": "tile_name",
         "normal_texture": "normal.png",
         "hover_texture": "hover.png",
         "details_texture": "details.png",
         "roof_texture": "roof.png",
         "ridge_color": "001144"
     }
 }

I tried using this idea but i am geeting error like:

Expression denotes a `type', where a "variable", "value" or "method group" was expected

when i use :

 using UnityEngine;
 using System.Collections;
 using LitJson;
 public class Loadr : MonoBehaviour {
 string url= "http://domain/site/get_texts.php"; //this is where i get my json
     
 void  Start (){
     WWW www = new WWW(url);
     print(www.text);
     var a = new LitJson.JsonReader(www.text);
     print(a.ToString());
     }
 }


How can i parse the json to access all the walls or all the tiles (in reality there will be more than then one) and access "name" property for e.g. ??

Comment
Add comment · Show 2
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 · Jun 08, 2012 at 03:07 PM 0
Share

Are you joking? The question you've linked is not a tutorial. Someone else also had a problem to use it because he used it wrong.

Have you even read the answer to the question?

avatar image rhose87 · Jun 08, 2012 at 03:46 PM 0
Share

sorry about that. i change it to "idea" :-D. I saw the answer and i didn't succeeded.

2 Replies

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

Answer by rutter · Jun 08, 2012 at 04:52 PM

This line:

 Object a = LitJson.JsonReader(www.text);

That's a constructor call, yes? If so, you'll need to use the new keyword:

 Object a = new LitJson.JsonReader(www.text);

Also, you might want to store the reference as something other than an Object. You may get a compiler error if the system thinks you meant UnityEngine.Object as opposed to System.Object.

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 rhose87 · Jun 08, 2012 at 05:04 PM 1
Share

What should i write ins$$anonymous$$d of Object ? LitJSON.JsonReader ?

avatar image Bunny83 · Jun 08, 2012 at 05:32 PM 3
Share

Yes, or just "var". That will automatically type the variable as LitJSON.JsonReader due to type inference.

avatar image rhose87 · Jun 11, 2012 at 01:59 PM 0
Share

i edited my project. now how can i parse the data ?

avatar image
1

Answer by podperson · Dec 29, 2012 at 09:36 PM

Try the newly improved JSONParse:

http://wiki.unity3d.com/index.php?title=Head_First_into_Unity_with_UnityScript

To parse the data you'd write:

var data : json = json.fromString( your_JSON );

to grab stuff out of it you use:

data._get( key ) (and it chains, so you can data._get("wall1")._get("_name").string_value;

Everything is nested json objects (see the code for further documentation).

I've been able to add a certain amount of syntax sugar for generating new json, but it's harder to make it work the other way.

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 hothead_ryan · Feb 05, 2014 at 07:01 PM 0
Share

You should at least add a disclaimer that you're the developer...

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

jSON data error Unity3d 0 Answers

LitJSON android problem 1 Answer

How to get object array from json? 0 Answers


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