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 /
  • Help Room /
avatar image
0
Question by Odessa_Int · Oct 05, 2017 at 01:00 PM · c#json

How to get nested json data

Hello,

I am getting data from an API as json and it come out like this:

 {
    "code":"5000157074454",
    "product":{ 
       "unknown_nutrients_tags":[
 
       ],
       "additives_old_tags":[
 
       ],
       "informers_tags":[
          "openfoodfacts-contributors"
       ],
       "product_name_en":"Tomato Ketchup ",..
       "states":"en:to-be-completed, en:nutrition-facts-to-be-completed, en:ingredients-to-be-completed, en:expiration-date-to-be-completed, en:packaging-code-to-be-completed, en:characteristics-to-be-completed, en:categories-to-be-completed, en:brands-completed, en:packaging-to-be-completed, en:quantity-completed, en:product-name-completed, en:photos-to-be-uploaded",
       "product_name":"Tomato Ketchup ",
       "ingredients_debug":[
 
       ],
       "product_name_debug_tags":[
 
       ],
       "entry_dates_tags":[
          "2017-09-27",
          "2017-09",
          "2017"
       ],
       "code":"5000157074454",
       "rev":2,
       "languages_codes":{
          "en":1
       },
       "nutrition_data_per":"100g",
       "additives_debug_tags":[
 
       ],
       "checkers_tags":[
 
       ],
       "quantity_debug_tags":[
 
       ],
       "editors_tags":[
          "openfoodfacts-contributors"
       ],
       "allergens":"",
       "ingredients_tags":[
 
       ],
       "interface_version_created":"20120622",
       "serving_quantity":0,
       "last_modified_by":null,
       "languages":{
          "en:english":1
       },
       "lang":"en",
       "creator":"openfoodfacts-contributors",
       "countries_hierarchy":[
          "en:united-kingdom"
       ],
       "countries":"en:GB",
       "quantity":"700g",
       "nutrient_levels_tags":[
 
       ],
       "nutriments":{
 
       },
       "languages_hierarchy":[
          "en:english"
       ],
       "additives_tags":[
 
       ],
       "ingredients":[
 
       ],
       "last_editor":null,
       "allergens_hierarchy":[
 
       ],
       "created_t":1506508630,
       "photographers_tags":[
 
       ],
       "ingredients_that_may_be_from_palm_oil_tags":[
 
       ],
       "brands_debug_tags":[
 
       ],
       "sortkey":506508686,
       "lc":"en",
       "allergens_tags":[
 
       ],
       "additives_prev_tags":[
 
       ],
       "interface_version_modified":"20150316.jqm2",
       "codes_tags":[
          "code-13",
          "5000157074454",
          "500015707445x",
          "50001570744xx",
          "5000157074xxx",
          "500015707xxxx",
          "50001570xxxxx",
          "5000157xxxxxx",
          "500015xxxxxxx",
          "50001xxxxxxxx",
          "5000xxxxxxxxx",
          "500xxxxxxxxxx",
          "50xxxxxxxxxxx",
          "5xxxxxxxxxxxx"
       ],
       "correctors_tags":[
 
       ],
       "additives_original_tags":[
 
       ],
       "no_nutrition_data":"",
       "nutrition_grades_tags":[
          "unknown"
       ],
       "states_hierarchy":[
          "en:to-be-completed",
          "en:nutrition-facts-to-be-completed",
          "en:ingredients-to-be-completed",
          "en:expiration-date-to-be-completed",
          "en:packaging-code-to-be-completed",
          "en:characteristics-to-be-completed",
          "en:categories-to-be-completed",
          "en:brands-completed",
          "en:packaging-to-be-completed",
          "en:quantity-completed",
          "en:product-name-completed",
          "en:photos-to-be-uploaded"
       ],
       "id":"5000157074454",
       "ingredients_text_with_allergens":null,
       "ingredients_text_debug":null,
       "ingredients_text_with_allergens_en":null,
       "brands":"Heinz",
       "countries_tags":[
          "en:united-kingdom"
       ],
       "last_edit_dates_tags":[
          "2017-09-27",
          "2017-09",
          "2017"
       ],
       "ingredients_ids_debug":[
 
       ],
       "states_tags":[
          "en:to-be-completed",
          "en:nutrition-facts-to-be-completed",
          "en:ingredients-to-be-completed",
          "en:expiration-date-to-be-completed",
          "en:packaging-code-to-be-completed",
          "en:characteristics-to-be-completed",
          "en:categories-to-be-completed",
          "en:brands-completed",
          "en:packaging-to-be-completed",
          "en:quantity-completed",
          "en:product-name-completed",
          "en:photos-to-be-uploaded"
       ],
       "additives_prev_original_tags":[
 
       ],
       "_keywords":[
          "tomato",
          "ketchup",
          "heinz"
       ],
       "nutrition_score_debug":"missing energy",
       "languages_tags":[
          "en:english",
          "en:1"
       ],
       "_id":"5000157074454",
       "complete":0,
       "nutrient_levels":{
 
       },
       "misc_tags":[
          "en:nutriscore-not-computed",
          "en:nutrition-not-enough-data-to-compute-nutrition-score",
          "en:nutrition-no-saturated-fat"
       ],
       "ingredients_from_palm_oil_tags":[
 
       ],
       "last_modified_t":1506508686,
       "brands_tags":[
          "heinz"
       ]
    },
    "status":1,
    "status_verbose":"product found"
 }

I want to see the items using Debug.Log I can do this for stuff that is on the top level but stuff that is nested, such as the stuff inside the "Product" section, I am unable to get to.

This is the bit of code I use to use the data once it has come through the API:

          jsonString = File.ReadAllText(dataPath);
         PulledData pulledData = JsonUtility.FromJson<PulledData>(jsonString);       
         
          Debug.Log(pulledData.status_verbose);

Any help will be greatly appiciated.

Thanks!

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
6
Best Answer

Answer by Bunny83 · Oct 05, 2017 at 01:15 PM

Well, how does your "PulledData" class look like? Though it's actually not very practical to parse this whole JSON structure into a class tree. You may want to use my SimpleJSON framework.

You can simply do things like this:

 JSONNode n = JSON.Parse( jsonString );
 
 string code = n["code"].Value;
 string productName = n["product"]["product_name"].Value;
 
 // or
 JSONNode product = n["product"];
 string productName = product["product_name"].Value;
 
 // prints all the "codes_tags" strings
 foreach(JSONNode item in product["codes_tags"].Children)
 {
     Debug.Log(item.Value);
 }
 
 // same as above
 JSONNode tags = product["codes_tags"];
 for(int i = 0; i < tags.Count; i++)
 {
     Debug.Log(tags[i].Value);
 }

All you need is to copy that "framework" into a file called SimpleJSON.cs in your project and when you want to use it, just add

 using SimpleJSON;

at the top of your script.

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 Odessa_Int · Oct 06, 2017 at 08:26 AM 0
Share

This is extremely useful thank you! In truth, I don't want to really parse all the data there are only 3-4 attributes that I need from it but that the data the API returns for me. However now I have got passed this with your help (I had an extremely un-optimized non-json way of doing it before) I can look into that.

Thank you so much for your help!

avatar image
-1

Answer by softpulsedev13 · Feb 09, 2019 at 12:56 PM

my json like this {"responseCode":1,"arrlstOurApps":[ {"title":"Fidget Spinner","desc":"The Fidget Spinner is amazing fidget simulator which rotates automatically but on touch it will change direction.\n
- Rotate Fidget Spinner and collect the matching ball raining from top.\n
- As you go, Spinner speed of rotation will continuosly increase.","img_url":"https:\/\/lh3.googleusercontent.com\/Bcc6l7atFMg7NWweljsKe8uipJJcOr9jEvjLt5VTcjTMMZZxATZTujiPJyQfoMi07VU=w300","redirect_url":"https:\/\/play.google.com\/store\/apps\/details?id=com.softpulse.spinnergame"}, {"title":"Balloon Pop and Learn","desc":"Balloon Pop and Learn is fun app for Kids, Toddler, Preschoolers.\nKids will enjoy the app with various balloons animations and sounds, App includs below variantions ;\n
- 1 to 20 Numbers\n
- A to Z small and capital alphabets\n
- Wild life animals\n
- Sea animals\n
- Birds","img_url":"https:\/\/lh3.googleusercontent.com\/Jn6ibTlrMzcNQ9oriXJgJcH21Qyt3lCxxhE5Jnk4big_9UzggU2sn_mV-WUMuzDX2UxD=w300","redirect_url":"https:\/\/play.google.com\/store\/apps\/details?id=com.softpulse.ballonpopandlearn"}]}

how can i deserealize it. and store it in this kind of list class. public class Data { public string data_name; public string data_dec; public string data_ImgUrl ; public string data_url ;

}

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

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

448 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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

Get Yelp API via Oauth in Unity- signature help needed 2 Answers

Loading JSON as a Text Asset using Resources.Load 1 Answer

Difference between serialization and saving data 2 Answers

How do you sort a list of JSONNodes by key value? 1 Answer

UnityWebRequest, C# request.accept equivalent? 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