0

I used the answer by @scozy on the post: How to convert HTML to JSON using PHP to convert my html to json on my server.

Then I am using a php post request to get this json file from the server into my android application.

On the android application, I want to convert this JSON back into HTML. Can someone please guide me here? I am completely new to JSON so some help here would be great.

P.S. I am using the HTML to JSON and then JSON to HTML for a reason.

EDIT: JSON is as follows

{
    "tag": "html",
    "lang": "en",
    "children": [
        {
            "tag": "head",
            "children": [
                {
                    "tag": "title",
                    "html": "  1448449425 = 2015-11-25 16:03:45 "
                }
            ]
        },
        {
            "tag": "body",
            "html": " ",
            "children": [
                {
                    "tag": "div",
                    "id": "update_date",
                    "html": "Nov 25, 2015 16:03"
                },
                {
                    "tag": "table",
                    "id": "stocks_data",
                    "children": [
                        {
                            "tag": "tr",
                            "children": [
                                {
                                    "tag": "td",
                                    "html": "Symbol"
                                },
                                {
                                    "tag": "td",
                                    "html": "Open Rate"
                                },
                                {
                                    "tag": "td",
                                    "html": "High Rate"
                                },
                                {
                                    "tag": "td",
                                    "html": "Low Rate"
                                },
                                {
                                    "tag": "td",
                                    "html": "Current Rate"
                                },
                                {
                                    "tag": "td",
                                    "html": "Price Change"
                                },
                                {
                                    "tag": "td",
                                    "html": "Volume"
                                }
                            ],
                            "html": " \t"
                        },
                        {
                            "tag": "tr",
                            "children": [
                                {
                                    "tag": "td",
                                    "html": "SYMBOL1"
                                },
                                {
                                    "tag": "td",
                                    "html": "41.49"
                                },
                                {
                                    "tag": "td",
                                    "html": "43.30"
                                },
                                {
                                    "tag": "td",
                                    "html": "40.21"
                                },
                                {
                                    "tag": "td",
                                    "html": "43.03"
                                },
                                {
                                    "tag": "td",
                                    "html": "1.79"
                                },
                                {
                                    "tag": "td",
                                    "html": "13,585,500"
                                }
                            ],
                            "html": " \t"
                        },
                        {
                            "tag": "tr",
                            "children": [
                                {
                                    "tag": "td",
                                    "html": "SYMBOL2"
                                },
                                {
                                    "tag": "td",
                                    "html": "39.50"
                                },
                                {
                                    "tag": "td",
                                    "html": "39.60"
                                },
                                {
                                    "tag": "td",
                                    "html": "38.25"
                                },
                                {
                                    "tag": "td",
                                    "html": "39.04"
                                },
                                {
                                    "tag": "td",
                                    "html": "0.21"
                                },
                                {
                                    "tag": "td",
                                    "html": "12,316,000"
                                }
                            ],
                            "html": " \t"
                        }
                     ]
                }
            ]
        }
    ]
}
Community
  • 1
  • 1
dejavu89
  • 754
  • 1
  • 7
  • 17
  • Please see the edit. Have posted the json – dejavu89 Nov 25 '15 at 11:09
  • @dejavu89 go through this tutorial, this may help you http://www.tutorialspoint.com/android/android_json_parser.htm – Nigam Patro Nov 25 '15 at 12:06
  • Why don't you send the HTML directly? What's the benefit of converting to JSON and back? – Henry Nov 25 '15 at 13:22
  • I have seen a situation where a local network / carrier is caching the php response (in html) despite headers asking not to cache. I was thinking that maybe returning in json format might not lead to caching? Or am I going the wrong way? – dejavu89 Nov 25 '15 at 16:36
  • If you find caching is done when it shouldn't it is always better to first try to solve this root problem rather than to implement a workaround. Btw. a simpler workaround may be to change the URL slightly between requests (for example add a timestamp). – Henry Nov 25 '15 at 19:01
  • I'm actually adding very large random numbers in the url, but caching is still done. which is very surprising to me. Only when users are using the app through a particular network, they face this issue. Other networks / wifi works perfectly fine. – dejavu89 Nov 25 '15 at 19:06

0 Answers0