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"
                        }
                     ]
                }
            ]
        }
    ]
}
6
  • Please see the edit. Have posted the json Commented Nov 25, 2015 at 11:09
  • @dejavu89 go through this tutorial, this may help you tutorialspoint.com/android/android_json_parser.htm Commented Nov 25, 2015 at 12:06
  • Why don't you send the HTML directly? What's the benefit of converting to JSON and back? Commented Nov 25, 2015 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? Commented Nov 25, 2015 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). Commented Nov 25, 2015 at 19:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.