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

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

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.


That data is in JSON format, so the easiest way to read it is using a JSON parser like

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 :frowning:

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):wink:
and used using Facebook.MiniJSON;