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 worldofcars · Mar 30, 2014 at 09:45 PM · facebookstringvaluegetresponse

Get values from long string (C#)

Hi I am currently integrating the Facebook Unity SDK in my game and when I load an app request, I get this result from facebook:

{ "id": "453305136468701", "application": { "name": "TEST_APP", "namespace": "test", "id": "1409535269881375" }, "to": { "name": "Recipient Name", "id": "100000195788968" }, "from": { "name": "Sender Name", "id": "100001527898169" }, "message": "TEST_APP is amazing! Check it out.", "created_time": "2014-03-29T16:32:33+0000" }

My question is now, how can I get for example the value of "id" from the field "from"?

Thank you in advance

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

5 Replies

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

Answer by trololo · Mar 30, 2014 at 10:06 PM

This is a JSON format file. Just use a json parsor (JSONObject in C# :)

Comment
Add comment · Show 4 · 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 trololo · Mar 30, 2014 at 10:08 PM 0
Share

You will be able to do something like jsonObj.GetField("name").str or jsonObj.GetField("number").n

avatar image worldofcars · Mar 31, 2014 at 03:50 PM 0
Share

Could you please give an example of how I can get from the "from" field the "id" value? ? I don't understand how Json works :(

avatar image trololo · Mar 31, 2014 at 05:09 PM 0
Share

You could use this external class: http://wiki.unity3d.com/index.php?title=JSONObject then you do

 JSONObject j = new JSONObject(theExampleStringYouGaveUs);
 string id = j.GetField("from").GetField("id").str;
avatar image worldofcars · Mar 31, 2014 at 07:42 PM 0
Share

That works perfectly! Thanks :)

avatar image
0

Answer by Scribe · Mar 30, 2014 at 10:07 PM

For this you can use the string.Split method which returns a string array splitting the string at the character(s) you define. For example:

 public string str;
     
 void Start () {
     string[] split = str.Split('"');
     for(int strIndex = 0; strIndex < split.Length; strIndex++){
         Debug.Log(split[strIndex] + " at index " + strIndex);
     }
         
     Debug.Log("For example the id is: " + split[3]);
 }

If you give this your sptring, it will return all the split strings and the last debug will return your id number.

Scribe

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 gfoot · Mar 31, 2014 at 08:22 AM

That data is in JSON format, so the easiest way to read it is using a JSON parser like http://wiki.unity3d.com/index.php/SimpleJSON

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 worldofcars · Mar 31, 2014 at 03:50 PM

Could somebody please give an example of how I can get from the "from" field the "id" value? ? I don't understand how Json works :(

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 paramama · May 10, 2014 at 11:40 AM

For example, you want to load id friends, who played in you games

private void QueryScores() { FB.API("/app/scores?fields=score,user.limit(20)", Facebook.HttpMethod.GET, ScoresCallback); }

void ScoresCallback(FBResult result) {

     scores = new List<object>();
     List<object> scoresList = Util.DeserializeScores(result.Text);
     foreach(object score in scoresList) 
     {
         var entry = (Dictionary<string,object>) score;
         var user = (Dictionary<string,object>) entry["user"];
         string userId = (string)user["id"];
                    //add id to Dictionary
             } 

}

Don't forget to login in FB (FB.Login("email,publish_actions,user_games_activity", LoginCallback);) and used using Facebook.MiniJSON;

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

24 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

Related Questions

Get "player value" from string 1 Answer

Help with GetType().GetField().GetValue() 1 Answer

how to assign the value of a string as variable 3 Answers

Public variable hidden in the inspector 2 Answers

assign string value from array to multiple game objects 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