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
1
Question by siddharth3322 · Jul 31, 2018 at 10:11 AM · facebookjsondictionaryparsing

Parse Json Response through Dictionary object

I have Json response through Facebook API like this:

alt text

Now I want to parse this data so I can use within my game. For this purpose, I have written code up to this:

     public void OnChallengesButtonClick ()
     {
         SoundManager.Instance.PlayButtonClickSound ();
 
         FB.API ("/me/friends", HttpMethod.GET, RetrieveFacebookFriends);
     }
 
     public void RetrieveFacebookFriends (IGraphResult result)
     {
         if (!string.IsNullOrEmpty (result.Error)) {
             Debug.Log ("ERROR: " + result.Error);
             return;
         }
 
         IDictionary<string,object> friendsDict = result.ResultDictionary;
 
         Debug.Log ("raw: " + result.RawResult);
     }

So how to extract Name and ID data from available Json response through Dictionary object? Please give me some help into this.

friends-list-json.png (11.3 kB)
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
1
Best Answer

Answer by Bunny83 · Jul 31, 2018 at 12:18 PM

Well you use a third party framework and probably haven't took the time reading through their documentation, right? They have an example over here.


You can use their Dictionary / List result if you want though you have to cast the "object" to the right type. I guess the ResultDictionary represents the top most object in the JSON structure. So to access the List you would do

 var dataList = (IList<object>)result.ResultDictionary["data"];

Now you can iterate through the objects like this:

 foreach(var obj in dataList)
 {
     var friend = (IDictionary<string, object>)obj;
     string name = (string)friend["name"];
     string id = (string)friend["id"];
     // do something
 }

This is just an assumption as i did not read the whole documentation.


Since they also provide the "RawResult" you could of course use a different Json parser. For example with my SimpleJSON you could just do

 var data = JSON.Parse(result.RawResult);
 foreach(var friend in data["data"])
 {
     string name = friend["name"];
     string id = friend["id"];
     // do something
 }

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 siddharth3322 · Jul 31, 2018 at 04:49 PM 0
Share

@Bunny83 Awesome answer, really thanks for your reply sir :)

avatar image babji3 · Apr 27, 2019 at 03:26 PM 0
Share

Hi i have same error am facing can you please give the suggesation?

avatar image babji3 · Apr 27, 2019 at 03:35 PM 0
Share

Am getting this error on ["data"] Please solve this issue. $$anonymous$$eyNotFoundException: The given key was not present in the dictionary. System.Collections.Generic.Dictionary`2[System.String,System.Object].get_Item (System.String key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)

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

90 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

Related Questions

Parsing Facebook graph JSON 1 Answer

forcing unload a file after error 0 Answers

Serialize / Deserialize dictionary with unity serialization system, without using lists for keys and values 1 Answer

Looking for Code that will Read JSON files (C# code) 2 Answers

How to parse Json file in android? 3 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