0

Is there a way to convert below text string to html string without using replace ?

Text String

 {"a":"\u003cul class=\"ylist ylist-bordered search-results\"\u003e\n\t\t\t\n\t\t\t\t\t\u003cli class=\"add-search-result\"\u003e\n\t\t\t\t\t\t\t\u003cdiv class=\"search-result yla biz-listing-large www-yla-unit-color-555555-ffefcb\" data-key=\"ad_business\"\u003e\n\t\t\t\u003cspan class=\"yla-tip\"\u003eYelp Ad\u003c/span\u003e\n\n\n\t\t\u003cdiv class=\"media-block media-block-large clearfix main-attributes\"\u003e\n\t\t\t\u003cdiv"}

HTML String

 

{"a": "<ul class=\"ylist ylist-bordered search-results\">\n\t\t\t\n\t\t\t\t\t<li class=\"add-search-result\">\n\t\t\t\t\t\t\t<div class=\"search-result yla biz-listing-large www-yla-unit-color-555555-ffefcb\" data-key=\"ad_business\">\n\t\t\t<span class=\"yla-tip\">Yelp Ad</span>\n\n\n\t\t<div class=\"media-block media-block-large clearfix main-attributes\">\n\t\t\t<div class=\"media-avatar\">\n\t\t\t\t\t\t\n\n\n\t<div class=\"photo-box biz-photo-box pb-90s\">\n\t\t\t<a href=\"/adredir?position=0&amp;redirect_url=http%3A%2F%2Fwww.yelp.com%2Fbiz%2Fez-pawn-corp-new-york-3&"}

I tried below code but its not working as expected (excel-vba)

 Dim html As Object
    Set html = CreateObject("htmlfile")
    html.body.innerText = strDiv
    Debug.Print   html.body.innerHTML

If i copy the text string to http://jsonlint.com/ to validate the string it returns the converted html string.

6
  • not trying to sound coy...but if ms dont provide a method, then you'll have to roll your own Commented Oct 11, 2013 at 4:03
  • + 1 I don't see a reason why this post was downvoted.... Commented Oct 11, 2013 at 6:57
  • 1
    Why not automate it? Send the string to the that page and retrieve the results? Commented Oct 11, 2013 at 6:57
  • @SiddharthRout sounds like an overkill :P and what is he going to do if the website vanishes? Commented Oct 11, 2013 at 7:21
  • 1
    @mehow: Since there is no inbuilt method, this is the only option. And if that link dies, he can move on to next ;) Commented Oct 11, 2013 at 7:22

1 Answer 1

1

This works for me. I have not added any error handling techniques. I am sure you can take care of that.

Sub Sample()
    Dim sURL As String: sURL = "http://jsonlint.com/"

    Dim StringtoConvert As String
    StringtoConvert = "{""a"":""\u003cul class=\""ylist ylist-bordered search-results\""\u003e\n\t\t\t\n\t\t\t\t\t\u003cli class=\""add-search-result\""\u003e\n\t\t\t\t\t\t\t\u003cdiv class=\""search-result yla biz-listing-large www-yla-unit-color-555555-ffefcb\"" data-key=\""ad_business\""\u003e\n\t\t\t\u003cspan class=\""yla-tip\""\u003eYelp Ad\u003c/span\u003e\n\n\n\t\t\u003cdiv class=\""media-block media-block-large clearfix main-attributes\""\u003e\n\t\t\t\u003cdiv""}"

    Dim ie As Object

    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True

    ie.navigate sURL

    Do While ie.readystate <> 4: Wait (1): Loop

    ie.document.getElementById("json_input").Value = StringtoConvert
    ie.document.getElementById("validate").Click

    Do While ie.readystate <> 4: Wait (1): Loop

    Debug.Print ie.document.getElementById("json_input").Value
End Sub

Private Sub Wait(ByVal nSec As Long)
    nSec = nSec + Timer
    While nSec > Timer
        DoEvents
    Wend
End Sub

Screenshot:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

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.