Volley Web Service with Genson

7 views
Skip to first unread message

Ömer Korkmaz

unread,
Sep 7, 2017, 8:57:11 AM9/7/17
to Genson user group
Hello friends. I am trying to pull data from json webservist with Volley and Genson. But it does not give an error, but it does not pull data. The problem is here. How can I access specificies data. How can I show ParseData.

  1. private void GetData()
  2. {
    RequestQueue queue = Volley.newRequestQueue(this);
    final String url = "https://api.github.com/users/mralexgray/repos";
    StringRequest postRequest = new StringRequest(Request.Method.GET, url,
    new Response.Listener<String>()
    {
  3. @Override
    public void onResponse(String response) {
    // response
    Log.d("Response", response);
    ParseData(response);
    }
    },
    new Response.ErrorListener()
    {
  4. @Override
    public void onErrorResponse(VolleyError error) {
    // error
    Log.d("Error.Response", error.getLocalizedMessage());
    }
    }
    )
    {
    };
  5. queue.add(postRequest);
  6. }
  7. private void ParseData(String data)
    {
    Genson genson = new Genson();
    try {
    Servis[] persons = genson.deserialize(data, Servis[].class);
    }
    catch (Exception e)
    {
    String hata = e.getLocalizedMessage();
    }
  8. }
  9. public class Servis implements Serializable {
  10. public String id;
  11. public String name;
  12. public String full_name;
  13. }


Eugen Cepoi

unread,
Sep 7, 2017, 2:32:15 PM9/7/17
to gen...@googlegroups.com
Hi,

Your ParseData method is doing nothing with the deserialized persons, same in case of an exception during the parsing you don't seem to do anything with it, so I'm not sure what you expect to happen... Maybe start with adding some logging/printing statements to print the parsed data.

There doesn't seem to be any Genson related issue, I'd suggest you to look for more documentation on how Volley works and how to use it.
Perhaps your problem is that it's providing you the results asynchronously and you don't know how to get them in a synchronous manner. There seem to be plenty of resources on internet explaining how to do a synchronous request.



--
You received this message because you are subscribed to the Google Groups "Genson user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genson+unsubscribe@googlegroups.com.
To post to this group, send email to gen...@googlegroups.com.
Visit this group at https://groups.google.com/group/genson.
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/1064ede4-03e5-4a85-880d-5a0f9c752d13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ömer Korkmaz

unread,
Sep 7, 2017, 4:22:57 PM9/7/17
to Genson user group
Can you say example please. Or can you try. 

7 Eylül 2017 Perşembe 21:32:15 UTC+3 tarihinde eugen yazdı:
To unsubscribe from this group and stop receiving emails from it, send an email to genson+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages