Exemplo n.º 1
0
        static void _Example2()
        {
            var url = "http://api.themoviedb.org/3/tv/2129?api_key=c83a68923b7fe1d18733e8776bba59bb";

            using (var reader = JsonTextReader.CreateFromUrl(url))
            {
                if (reader.SkipToField("created_by"))
                {
                    // we're currently on the *key*/field name
                    // we have to move to the value if we want
                    // just that.
                    // finally, we parse the subtree into a
                    // tree of objects, and write that to the
                    // console, which pretty prints it
                    if (reader.Read())
                    {
                        Console.WriteLine(reader.ParseSubtree());
                    }
                    else                     // below should never execute
                    {
                        Console.WriteLine("Sanity check failed, key has no value");
                    }
                }
                else
                {
                    Console.WriteLine("Not found");
                }
            }
        }
Exemplo n.º 2
0
        static void _Example6()
        {
            var url = "http://api.themoviedb.org/3/tv/2129?api_key=c83a68923b7fe1d18733e8776bba59bb";

            using (var reader = JsonTextReader.CreateFromUrl(url))
            {
                // accept either "seasons" or "production_companies" - whichever comes first
                if (reader.SkipToAnyOfFields("seasons", "production_companies"))
                {
                    // we're currently on the *key*/field name
                    // we have to move to the value if we want
                    // just that.
                    if (reader.Read())
                    {
                        Console.WriteLine(reader.ParseSubtree());
                    }
                    else                     // below should never execute
                    {
                        Console.WriteLine("Sanity check failed, key has no value");
                    }
                }
                else
                {
                    Console.WriteLine("Not found");
                }
            }
        }
Exemplo n.º 3
0
        static void _Example5()
        {
            var url = "http://api.themoviedb.org/3/tv/2129?api_key=c83a68923b7fe1d18733e8776bba59bb";

            using (var reader = JsonTextReader.CreateFromUrl(url))
            {
                // skip to "$.created_by[1].name" <-- JSON path syntax
                if (reader.SkipTo("created_by", 1, "name"))
                {
                    // we're currently on the *key*/field name
                    // we have to move to the value if we want
                    // just that.
                    if (reader.Read())
                    {
                        Console.WriteLine(reader.ParseSubtree());
                    }
                    else                     // below should never execute
                    {
                        Console.WriteLine("Sanity check failed, key has no value");
                    }
                }
                else
                {
                    Console.WriteLine("Not found");
                }
            }
        }
Exemplo n.º 4
0
        static void _Example7()
        {
            var url = "http://api.themoviedb.org/3/tv/2129?api_key=c83a68923b7fe1d18733e8776bba59bb";

            using (var reader = JsonTextReader.CreateFromUrl(url))
            {
                // skip to "$.created_by[1].name" <-- JSON path syntax
                if (reader.SkipTo("created_by", 0, "name"))
                {
                    // we're currently on the *key*/field name
                    // we have to move to the value if we want
                    // just that.
                    if (reader.Read())
                    {
                        Console.WriteLine(reader.ParseSubtree());
                    }
                    else                     // below should never execute
                    {
                        Console.WriteLine("Sanity check failed, key has no value");
                    }
                    // we need to move outward in the tree
                    // so we can read the next array element
                    // so we skip the rest of this object
                    reader.SkipToEndObject();
                    if (reader.Read())                     // read past the end of the object
                    {
                        // we're on the next object so get the name
                        reader.SkipToField("name");
                        // we're currently on the *key*/field name
                        if (reader.Read())
                        {
                            Console.WriteLine(reader.ParseSubtree());
                        }
                        else                         // below should never execute
                        {
                            Console.WriteLine("Sanity check failed, key has no value");
                        }
                    }
                    else                     // below should never execute, we didn't expect to reach the end
                    {
                        Console.WriteLine("Sanity check failed, unexpected end of document");
                    }
                }
                else
                {
                    Console.WriteLine("Not found");
                }
            }
        }
Exemplo n.º 5
0
 static void _Example4()
 {
     using (var reader = JsonTextReader.CreateFromUrl("http://api.themoviedb.org/3/tv/2129?api_key=c83a68923b7fe1d18733e8776bba59bb"))
     {
         // skip to "$.created_by[1]" <-- JSON path syntax
         if (reader.SkipTo("created_by", 1))
         {
             Console.WriteLine(reader.ParseSubtree());
         }
         else
         {
             Console.WriteLine("Not found");
         }
     }
 }
Exemplo n.º 6
0
        static void Main()
        {
            var url = "http://api.themoviedb.org/3/tv/2129?api_key=c83a68923b7fe1d18733e8776bba59bb";

            using (var reader = JsonTextReader.CreateFromUrl(url))
            {
                // skip to "$.created_by[1].name" <-- JSON path syntax
                if (reader.SkipTo("created_by", 0, "name"))
                {
                    // we're currently on the *key*/field name
                    // we have to move to the value if we want 
                    // just that.
                    if (reader.Read())
                    {
                        Console.WriteLine(reader.ParseSubtree());
                    }
                    else                     // below should never execute
                    {
                        Console.WriteLine("Sanity check failed, key has no value");
                    }
                    // we need to move outward in the tree
                    // so we can read the next array element
                    // so we skip the rest of this object
                    reader.SkipToEndObject();
                    if (reader.Read())                     // read past the end of the object
                    {
                        reader.SkipToField("name");
                        // we're currently on the *key*/field name
                        if (reader.Read())
                        {
                            Console.WriteLine(reader.ParseSubtree());
                        }
                        else                         // below should never execute
                        {
                            Console.WriteLine("Sanity check failed, key has no value");
                        }
                    }
                    else                     // below should never execute, we didn't expect to reach the end
                    {
                        Console.WriteLine("Sanity check failed, unexpected end of document");
                    }
                }
                else
                {
                    Console.WriteLine("Not found");
                }
            }
            return;

            using (var reader = JsonTextReader.CreateFromUrl("http://api.themoviedb.org/3/tv/2129?api_key=c83a68923b7fe1d18733e8776bba59bb"))
            {
                // skip to "$.created_by[1].name" <-- JSON path syntax
                if (reader.SkipTo("created_by", 1, "name"))
                {
                    // we're currently on the *key*/field name
                    // we have to move to the value if we want 
                    // just that.
                    if (reader.Read())
                    {
                        Console.WriteLine(reader.ParseSubtree());
                    }
                    else                     // below should never execute
                    {
                        Console.WriteLine("Sanity check failed, key has no value");
                    }
                }
                else
                {
                    Console.WriteLine("Not found");
                }
            }
            return;

            using (var reader = JsonTextReader.CreateFrom(@"..\..\data.json"))
            {
                while (reader.Read())
                {
                    Console.Write(reader.NodeType);
                    if (JsonNodeType.Value == reader.NodeType ||
                        JsonNodeType.Key == reader.NodeType)
                    {
                        Console.Write(" " + reader.Value);
                    }
                    Console.WriteLine();
                }
            }
            return;

            using (var reader = JsonTextReader.CreateFrom(@"..\..\data.json"))
            {
                if (reader.SkipTo("seasons", 7, "episodes", 3, "guest_stars", 0, "character"))
                {
                    // move past the field name if it's a key.
                    if (JsonNodeType.Key != reader.NodeType || reader.Read())
                    {
                        Console.WriteLine(reader.ParseSubtree());
                    }
                }
            }
            // or...
            using (var reader = JsonTextReader.CreateFrom(@"..\..\data.json"))
            {
                if (reader.SkipToField("created_by"))
                {
                    if (reader.SkipToIndex(0))
                    {
                        reader.Read();
                        if (reader.SkipToField("name"))
                        {
                            if (reader.Read())
                            {
                                Console.WriteLine(reader.Value);
                            }
                        }
                    }
                }
            }

            return;

            Tmdb.ApiKey     = ApiKey;
            Tmdb.CacheLevel = JsonRpcCacheLevel.Aggressive;

            // hit it *hard* - 10 pages of movies, 10 of TV
            foreach (var movie in TmdbMovie.GetTopRated(0, 9))
            {
                _RunMovieDemo(movie.Id);
            }

            foreach (var show in TmdbShow.GetTopRated(0, 9))
            {
                _RunShowDemo(show.Id);
            }
        }