HasProperty() 공개 메소드

public HasProperty ( string prop ) : bool
prop string
리턴 bool
예제 #1
0
        // process all tweets in tweetStringQueue
        void Parse()
        {
            while (true)
            {
                while (!isParsingPaused && tweetStringQueue.Count > 0)
                {
                    string newTweetStr = tweetStringQueue.Dequeue();

                    try
                    {
                        JSONObject newObj = new JSONObject(newTweetStr);

                        if (newObj.HasProperty("text"))
                        {
                            Tweet newTweet = new Tweet(newObj);
                            tweets.Enqueue(newTweet);
                        }
                        else if (newObj.HasProperty("limit"))
                        {
                            curLimit = newObj.GetProperty("limit").GetProperty("track").n;
                        }
                        else
                        {
                            Console.WriteLine("Unrecognised (valid) JSON object in stream");
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Invalid object in json string");
                    }
                }

                Thread.Sleep(100);
            }
        }
예제 #2
0
        // extract coords from location object
        public static Coordinates[] GetLocationData(JSONObject locationObj)
        {
            try
            {
                if (locationObj.HasProperty("coordinates"))
                {
                    List <JSONObject> coords = locationObj.GetProperty("coordinates").props;
                    if (coords.Count % 2 != 0)
                    {
                        throw new System.Exception("Wrong coordinate setup?");
                    }

                    Coordinates[] toRet = new Coordinates[coords.Count / 2];
                    for (int i = 0; i < coords.Count; i += 2)
                    {
                        toRet[i] = new Coordinates((float)coords[i + 1].n, (float)coords[i].n);
                    }
                    return(toRet);
                }

                throw new System.Exception("wrong geo type");
            } catch (System.Exception e)
            {
                Console.WriteLine("Location error:" + e.Message);
                return(new Coordinates[2]);
            }
        }
예제 #3
0
        // process all tweets in tweetStringQueue
        void Parse()
        {
            while ( true )
            {
                while ( !isParsingPaused && tweetStringQueue.Count > 0 )
                {
                    string newTweetStr = tweetStringQueue.Dequeue();

                    try
                    {
                        JSONObject newObj = new JSONObject( newTweetStr );

                        if ( newObj.HasProperty( "text" ) )
                        {
                            Tweet newTweet = new Tweet( newObj );
                            tweets.Enqueue ( newTweet );
                        }
                        else if ( newObj.HasProperty ( "limit" ) )
                            curLimit = newObj.GetProperty( "limit" ).GetProperty ( "track" ).n;
                        else
                            Console.WriteLine ( "Unrecognised (valid) JSON object in stream" );
                    }
                    catch
                    {
                        Console.WriteLine( "Invalid object in json string" );
                    }
                }

                Thread.Sleep ( 100 );
            }
        }
예제 #4
0
        // extract coords from location object
        public static Coordinates[] GetLocationData( JSONObject locationObj )
        {
            try
            {
                if ( locationObj.HasProperty( "coordinates" ) )
                {
                    List<JSONObject> coords = locationObj.GetProperty ( "coordinates" ).props;
                    if ( coords.Count % 2 != 0 )
                        throw new System.Exception( "Wrong coordinate setup?" );

                    Coordinates[] toRet = new Coordinates[ coords.Count / 2 ];
                    for ( int i = 0; i < coords.Count; i += 2 )
                    {
                        toRet[i] = new Coordinates( (float)coords[i+1].n, (float)coords[i].n );
                    }
                    return toRet;
                }

                throw new System.Exception( "wrong geo type" );

            } catch ( System.Exception e )
            {
                Console.WriteLine( "Location error:" + e.Message );
                return new Coordinates[2];
            }
        }