Question

I have looked all over for an answer to this and I don't see one.

A little history of what I am working with. I am loading XML from one server, converting it to a JSON file on my server, so I can easily work with it (using JS).

My json looks like this:

{ "listings": [{ "detailsLink": "http://idx.firstidx.com/NewDetails.aspx?MLS=2529220&TableType=SingleFamily&DatabaseID=50&Domain=639 ", "detailsPrice": "149000", "detailsBeds": "0", "detailsBaths": "1", "detailsCity": "Floral Park", "detailsImage": "http://3pv.mlsstratus.com/mlsmultiphotos/full/1/220/2529220.jpg", "detailsState": "NY" }]}

My jquery looks like this:

$.getJSON('get-json.asp', function(data){
    $.each(data.listings, function(i,l){
        var detailsLink     = l.detailsLink;
        var detailsImage    = l.detailsImage;
        var detailsPrice    = l.detailsPrice;
        var detailsBeds     = l.detailsBeds;
        var detailsBaths    = l.detailsBaths;
        var detailsCity     = l.detailsCity;
        var detailsState    = l.detailsState;

    // Here is where I plan to do magical things with my new variables.

    });
});

The callback function isn't firing for me. When I remove the detailsLink from the JSON file it is firing without any issue. The detailsImage isn't causing an error.

I checked to see if my JSON was valid with a free service online and if I paste the JSON in by hand it comes up clean but when I load it from the URL it is showing the detailsLink to have an invalid character.

Is there something that I need to do to prepare my detailsLink (URL) for JSON output?

Thanks in advance.

Here is the VB for my ASP file:

Set listings = xml.getElementsByTagName("PropertyDetails")
        Response.Write "{"
        Response.Write " ""listings"": ["
        For i = 0 to (listings.Length-1)

            Response.Write "{"

            Response.Write " ""detailsPrice"":" &  " """ & listings.item(i).childNodes(11).text &  """, "
            Response.Write " ""detailsLink"":" &  " """ & listings.item(i).childNodes(0).text &  """, "
            Response.Write " ""detailsBeds"":" &  " """ & listings.item(i).childNodes(8).text &  """, "
            Response.Write " ""detailsBaths"":" &  " """ & listings.item(i).childNodes(9).text &  """, "
            Response.Write " ""detailsCity"":" &  " """ & listings.item(i).childNodes(4).text &  """, "
            Response.Write " ""detailsImage"":" &  " """ & listings.item(i).childNodes(15).text &  """, "
            Response.Write " ""detailsState"":" &  " """ & listings.item(i).childNodes(6).text &  """ "

        if i < (listings.length-1) then 'If this is not the last listing add a comma after the curley brace

            Response.Write "},"
            else
             Response.Write "}" 'This is the last listing, so no comma
        end if
        Next
        Response.Write "]"
        Response.Write "}"
Was it helpful?

Solution

Okay, after looking further in to this, I can see that I didn't have any JSON header info being read by my Jquery on the front side of the site.

Instead of writing that out by hand too, I decided to use a library that can do it for me on the VB (ASP) side.

The class that I used is located a: http://www.aspjson.com/

Thanks for the help you guys.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top