SetBookTitle() public méthode

public SetBookTitle ( string title ) : void
title string
Résultat void
Exemple #1
0
    /// <summary>
    /// Parses a JSON string and returns a book data struct from that
    /// </summary>
    public BookData ParseString(string val)
    {
        BookData bookData = new BookData();

        string[] jsonLines = val.Split(',');

        foreach (string line in jsonLines)
        {
            string[] elements = line.Split(':');
            if (elements.Length > 1)
            {
                string jsonKey = GetJSONValue(elements[0]);

                if (jsonKey.Equals(TITLE_KEY))
                {
                    bookData.SetBookTitle(GetJSONValue(elements[1]));
                }
                else if (jsonKey.Equals(AUTHOR_KEY))
                {
                    bookData.SetBookAuthor(GetJSONValue(elements[1]));
                }
                else if (jsonKey.Equals(AVERAGE_RATING_KEY))
                {
                    bookData.SetBookRating(int.Parse(GetJSONValue(elements[1])));
                }
                else if (jsonKey.Equals(NUMB_OF_RATINGS_KEY))
                {
                    bookData.SetBookOverallRating(int.Parse(GetJSONValue(elements[1])));
                }
                else if (jsonKey.Equals(LIST_PRICE_KEY))
                {
                    bookData.SetBookRegularPrice(float.Parse(GetJSONValue(elements[1])));
                }
                else if (jsonKey.Equals(YOUR_PRICE_KEY))
                {
                    bookData.SetBookYourPrice(float.Parse(GetJSONValue(elements[1])));
                }
                else if (jsonKey.Equals(THUMB_URL_KEY))
                {
                    string thumbUrl = "";
                    for (int j = 1; j < elements.Length; j++)
                    {
                        thumbUrl += elements[j];
                        if (j == 1)
                        {
                            thumbUrl += ":";
                        }
                    }

                    bookData.SetBookThumbUrl(GetJSONValue(thumbUrl));
                }
                else if (jsonKey.Equals(BOOK_URL_KEY))
                {
                    string bookUrl = "";
                    for (int j = 1; j < elements.Length; j++)
                    {
                        bookUrl += elements[j];
                        if (j == 1)
                        {
                            bookUrl += ":";
                        }
                    }

                    bookData.SetBookDetailUrl(GetJSONValue(bookUrl));
                }
            }
        }

        return(bookData);
    }
Exemple #2
0
    /// <summary>
    /// fetches the JSON data from a server
    /// </summary>
    private IEnumerator LoadJSONBookData(string jsonBookUrl)
    {
        // Gets the full book json url
        string fullBookURL = JsonServerUrl + jsonBookUrl;

        // Gets the json book info from the url
        mJsonBookInfo = new WWW(fullBookURL);
        yield return mJsonBookInfo;

        // Loading done
        mIsLoadingBookData = false;

        if (mJsonBookInfo.error == null)
        {
            // Parses the json Object
            JSONParser parser = new JSONParser();

            BookData bookData = parser.ParseString(mJsonBookInfo.text);
            mBookData = bookData;

            // Updates the BookData info in the augmented object
            mBookInformationParser.UpdateBookData(bookData);

            mIsLoadingBookThumb = true;
        }
        else
        {
            //Debug.LogError("Error downloading json");
            BookData bookData = new BookData();
            bookData.SetBookTitle("The Hunger Game");
            bookData.SetBookAuthor("Suzanne Collins");
            bookData.SetBookRating(4);
            bookData.SetBookOverallRating(23933);
            bookData.SetBookRegularPrice(10.99f);
            bookData.SetBookYourPrice(7.09f);
            bookData.SetBookThumbUrl("http://ecx.images-amazon.com/images/I/41bOj-am1RL._SX331_BO1,204,203,200_.jpg");
            bookData.SetBookDetailUrl("http://www.amazon.com/The-Hunger-Games-Book-1/dp/0439023521/ref=pd_bxgy_14_img_z");

            mBookData = bookData;
            Debug.Log("mBookData assigned");

            // Updates the BookData info in the augmented object
            mBookInformationParser.UpdateBookData(bookData);

            mIsLoadingBookThumb = true;
        }
    }
Exemple #3
0
    /// <summary>
    /// Parses a JSON string and returns a book data struct from that
    /// </summary>
    public BookData ParseString(string val)
    {
        BookData bookData = new BookData();
        string[] jsonLines = val.Split(',');

        foreach (string line in jsonLines)
        {
            string[] elements =  line.Split(':');
            if(elements.Length > 1)
            {
                string jsonKey = GetJSONValue(elements[0]);

                if(jsonKey.Equals(TITLE_KEY))
                {
                    bookData.SetBookTitle(GetJSONValue(elements[1]));

                }
                else if(jsonKey.Equals(AUTHOR_KEY))
                {
                    bookData.SetBookAuthor(GetJSONValue(elements[1]));

                }
                else if(jsonKey.Equals(AVERAGE_RATING_KEY))
                {
                    bookData.SetBookRating(int.Parse(GetJSONValue(elements[1])));

                }
                else if(jsonKey.Equals(NUMB_OF_RATINGS_KEY))
                {
                    bookData.SetBookOverallRating(int.Parse(GetJSONValue(elements[1])));

                }
                else if(jsonKey.Equals(LIST_PRICE_KEY))
                {
                    bookData.SetBookRegularPrice(float.Parse(GetJSONValue(elements[1])));

                }
                else if(jsonKey.Equals(YOUR_PRICE_KEY))
                {
                    bookData.SetBookYourPrice(float.Parse(GetJSONValue(elements[1])));

                }
                else if(jsonKey.Equals(THUMB_URL_KEY))
                {
                    string thumbUrl = "";
                    for(int j=1; j < elements.Length; j++)
                    {
                        thumbUrl += elements[j];
                        if(j == 1)
                        {
                            thumbUrl += ":";
                        }
                    }

                    bookData.SetBookThumbUrl(GetJSONValue(thumbUrl));

                }
                else if(jsonKey.Equals(BOOK_URL_KEY))
                {
                    string bookUrl = "";
                    for(int j=1; j< elements.Length; j++)
                    {
                        bookUrl += elements[j];
                        if(j == 1)
                        {
                            bookUrl += ":";
                        }
                    }

                    bookData.SetBookDetailUrl(GetJSONValue(bookUrl));
                }
            }
        }

        return bookData;
    }