Hi mates,
I’m trying to retrieve Facebook’s friend scores using prime31 Social Plugin and have a problem deserializing a numeric value.
I only want to save the retrieved numeric scores but keep getting problems.
I can deserialize the strings, but keep getting errors when trying to deserialize the numeric “score” values.
I get this error in this line: double score = (((IDictionary) ht)[“score”]);
InvalidCastException: Cannot cast from source type to destination type.
How should I do to store the score variable?
I have tried all I could imagine…, please give me some tips.
Thanks in advance!
This is my json structure.
{
"data": [
{
"user": {
"name": "Jaume",
"id": "709353319"
},
"score": 20,
"application": {
"name": "MiniBasket",
"namespace": "minibasket",
"id": "572013964869884"
}
},
{
"user": {
"name": "Jordi",
"id": "639588441"
},
"score": 0,
"application": {
"name": "MiniBasket",
"namespace": "minibasket",
"id": "572013964869884"
}
}
]
}
And here is my OnLeaderboardComplete method.
void OnLeaderboardComplete( string error, object result ) {
Debug.Log("Facebook >> OnLeaderboardComplete");
Debug.Log(" >>> result: " + result);
Prime31.Utils.logObject( result );
var scoreResults = result as IDictionary;
var list = scoreResults["data"] as IList;
userListNames = new List<string>();
userListScores = new List<double>();
leaderboardTotal = list.Count;
leaderboardCount = 0;
for(int i = 0; i < list.Count; i++)
{
var ht = list *as IDictionary;*
-
var user = ht["user"] as IDictionary;*
-
double score = (((IDictionary<string, double>) ht)["score"]); *
string id = user[“id”] as string;
-
string name = user["name"] as string;*
-
name = name.Split(' ')[0] as string;*
-
if (currentId.ToString() == id) name += " (me)";*
-
Debug.Log("id: " + id + " , name: " + name + " , score: " + score);*
-
// store stuff*
-
userListNames.Add(name);*
-
userListScores.Add(score); *
}
}