-6

I have my response

{
  "status_code": 200,
  "body": {
    "canCreate": 0,
    "totalItemCount": 76,
    "response": [
      {
        "blog_id": 182,
        "title": "Test Blog",
        "body": "<p>dSsadasddaasd<\/p>\r\n<p><img src=\"\/seapidev\/public\/album_photo\/7c\/04\/0478_3c26.png?c=440c\" alt=\"\"><\/p>",
        "owner_type": "user",
        "owner_id": 1,
        "category_id": 1,
        "creation_date": "2015-04-22 07:16:28",
        "modified_date": "2015-04-22 07:16:28",
        "view_count": 3,
        "comment_count": 0,
        "search": 1,
        "draft": 0,
        "category_title": "Arts & Culture",
        "url": "http:\/\/dev1.bigsteptech.in\/seapidev\/blogs\/1\/182\/test-blog",
        "owner_url": "http:\/\/dev1.bigsteptech.in\/seapidev\/profile\/admin",
        "owner_image": "http:\/\/dev1.bigsteptech.in\/seapidev\/public\/user\/69\/04\/0465_82ca.png?c=b4e4",
        "owner_title": "SocialEngineAddOns Admin",
        "allow_to_view": 1
      }
    ]
  }
}

I want to convert it in Gson and then read it, how can I replicate this file structure in my project??

Can you please help me as I am new to android.

Thanks in advance...

Maveňツ
  • 1
  • 12
  • 50
  • 89
user3256822
  • 135
  • 1
  • 7
  • please make a good research before ask questions, there has a lot of web pages that can help you. Your response is JSON so you can just get the string and convert it in to JSON object or if you want more just follow links [link] (http://stackoverflow.com/questions/18192891/conversion-from-string-to-json-object-android) [link] (http://www.mkyong.com/java/how-do-convert-java-object-to-from-json-format-gson-api/) – Stoycho Andreev Apr 29 '15 at 07:44

2 Answers2

0

Create a Java class that is the Java equivalent of the JSON you could use a site like: json2pojo (http://www.jsonschema2pojo.org/) to do this for you.

Then to convert the JSON to the Java object you can do the following:

Gson = new Gson();
Object obj = (Object) gson.fromJson(json, Object.class);

Where Object is your custom object.

Tim Kranen
  • 4,202
  • 4
  • 26
  • 49
  • { "status_code": 200, "body": { "canCreate": 0, "totalItemCount": 76, "response": [ { "blog_id": 182, "title": "Test Blog", "owner_image": "http:\/\/dev1.bigsteptech.in\/seapidev\/public\/user\/69\/04\/0465_82ca.png?c=b4e4", "owner_title": "SocialEngineAddOns Admin", } ] I want to read the status_code , response inside body, how can I do this. Please help me here. Thanks – user3256822 Apr 29 '15 at 07:43
  • Please specify the question. You just want the status code? – Tim Kranen Apr 29 '15 at 07:45
  • Thanks for this it is amazing and solved my problem. I have one other issue also, I want to generate a form in android according to my Json Data, can you please help me how can I do this ?? – user3256822 Apr 30 '15 at 08:16
  • @user3256822 Glad I could help! I would appreciate it if you would accept the answer. If you have another question you can start a chat and I'll be willing to help you out! – Tim Kranen Apr 30 '15 at 08:22
  • Thanks you so much for such a nice support Tim, I really appreciate it. StackOverflow is just like a second life for developers, you guys are really good, thanks again for your support. I want ask one question. I am having a json response and I want to create a form according to this json response with some fields like EditText, Select Box type and so on, can you please help me out here, that how can I generate the form like this in android. Is there any way to do this in android. Please help me here. Thanks you so much in advance. :) :) – user3256822 Apr 30 '15 at 08:26
  • Can you please give me just an idea about how to implement this or can give some references so that I can continue with them and can solve my issue. Thanks – user3256822 Apr 30 '15 at 09:39
  • In Volley Post Request, I want to send post parameters with it. I know about the protected Map getParams(){ Map params = new HashMap(); params.put("user",userAccount.getUsername()); params.put("pass",userAccount.getPassword()); params.put("comment", Uri.encode(comment)); params.put("comment_post_ID",String.valueOf(postId)); params.put("blogId",String.valueOf(blogId)); return params; } – user3256822 May 06 '15 at 05:23
  • But with this we can send only the string parameters, how can I send the integer values also, with this. Can you please tell me. – user3256822 May 06 '15 at 05:30
  • What about converting the int to a string temporarily? Like "int". – Tim Kranen May 06 '15 at 07:25
0

Try http://www.jsonschema2pojo.org/ to generate all the classes you need

BlackBishop
  • 737
  • 1
  • 7
  • 18
  • Thanks for this it is amazing and solved my problem. I have one other issue also, I want to generate a form in android according to my Json Data, can you please help me how can I do this ?? – user3256822 Apr 30 '15 at 08:12