1. #1
    Touch Premium Member
    Join Date
    Mar 2008
    Location
    Morgan Hill, CA
    Posts
    126
    Vote Rating
    3
    margozzi is on a distinguished road

      0  

    Default Unanswered: How to get a JsonReader to read a single JSON Object?

    Unanswered: How to get a JsonReader to read a single JSON Object?


    All of the examples are for LIsts of data. I want to read a single JSON object and convert it to an AutoBean. I have tried without success for a while now. I have also googled around extensively.

    How would I read in an object like:
    Code:
    { foo: 10, bar: "hello" }
    I would even be happy with being able to read:
    Code:
    data: { foo: 10, bar: "hello" }

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,731
    Answers
    109
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    What have you tried? What does your autobean look like? Do you get any error messages?

    Are you trying to read a single object like that, or a full list of them? Usually the DataReader api (and so JsonReader) is used to read lists on behalf of a Loader/Proxy, so when you need individual objects, you just use the AutoBeanCodex directly, calling decode with the right factory type, autobean type, and the string itself.

    Note please that neither string is JSON, though the first is at least close. You must quote your key names:
    Code:
    { "foo": 10, "bar": "hello" }

  3. #3
    Touch Premium Member
    Join Date
    Mar 2008
    Location
    Morgan Hill, CA
    Posts
    126
    Vote Rating
    3
    margozzi is on a distinguished road

      0  

    Default


    I used a JasonWriter like this:
    Code:
    JsonWriter<System> writer = new JsonWriter<System>(factory,System.class);
    It has no "Base" parameter. It generates JSON without a root.

    I wanted to do the same, but JasonReader wants a "Base"
    Code:
    JsonReader<System, Base> reader = new JsonReader<System, Base>(_beanFactory, Base.class);
    I was hoping to get a simple object with having to have a root node.
    I would like to read in:

    Code:
    { "foo": 10, "bar": "hello" }
    \

    I was able to get this to work:
    Code:
    { data: { "foo": 10, "bar": "hello" } }
    P.S. I believe you need not quote the keys unless they are reserved keywords in JavaScript.
    Always quoting them is obviously safer, but not mandatory. The quotes do add to the payload size.

  4. #4
    Touch Premium Member
    Join Date
    Mar 2008
    Location
    Morgan Hill, CA
    Posts
    126
    Vote Rating
    3
    margozzi is on a distinguished road

      0  

    Default


    AutoBeanCodex worked like a champ!
    Thank you very much for the quick response!

  5. #5
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,731
    Answers
    109
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Glad to hear it worked.

    JsonReader's Base generic arguement is not always required, as you noted. In that case, you must specify the Result argument twice. This is the default - createReturnData will just return the base object as if it were the result.

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi