0

This is my code :

  var client = new FacebookClient(token);
 dynamic result = client.Get("search?q=tbilisi&type=user", new {  });

result.data is an array, how to determine if it's an empty array. For example what i'm trying to do :

 while (true)
 {
     if (result == null)
     {
         break;
     }
     if (result.data ==  null )
     {
         break;
     }

But not woks. When result.data = [] i want to check and break while loop.

3
  • Use result.count instead of .length maybe? Commented Dec 17, 2015 at 9:03
  • Same error, it is json array object Commented Dec 17, 2015 at 9:04
  • 1
    If you do know type of object why do you use dynamic ? Commented Dec 17, 2015 at 9:05

4 Answers 4

9
var array = result.data as Facebook.JsonArray;
if (array == null || array.Count == 0)
Sign up to request clarification or add additional context in comments.

7 Comments

It is dynmic object and doesn't have Length property
Runtime error : 'Facebook.JsonArray' does not contain a definition for 'Length'
@NikaJavakhishvili so, you have JsonArray object
Same error , it doesn't have any property, i think need to cast
I've to use jsonserilizer, but can't figure out how
|
1
while (true)
{
     if (result == null)
     {
         break;
     }
     if (result.data ==  null || !result.data.Any())
     {
         break;
     }
}

Comments

0

while (result.data.length >0) { your code here }

Comments

0

This one works for me:

if (object == null || ((JArray)object).Count == 0) { // code }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.