2

Google Voice has XML URLs so I was wondering how somebody would pull the JSON part from the returned XML and parse it out to a page. Google Voice's search capability is busted right now and I want to get access to my history. I'm thinking that a synchronous call to all of the pages up to the last known page number in my history should do it...

Kristopher
  • 819
  • 14
  • 31

2 Answers2

2

This may be your best bet...

Read about dataType conversion here: http://api.jquery.com/extending-ajax/

Particularly the section that says:

You can define converters "inline," inside the options of an ajax call. For example, the following code requests an XML document, then extracts relevant text from it, and parses it as "mydatatype":

$.ajax( url, {
  dataType: "xml text mydatatype",
  converters: {
    "xml text": function( xmlValue ) {
      // Extract relevant text from the xml document
      return textValue;
    }
  }
});

I don't know if this exact code snippet will return the JSON content properly, but at the very least it should strip it out of the XML response (you may need to add additional code to parse the returned "textValue" as JSON. Perhaps using the jQuery parseJSON method.

Maybe try:

$.ajax( url, {
  dataType: "xml text mydatatype",
  converters: {
    "xml text": $.parseJSON;
    }
  }
});

Hope this helps.

therealklanni
  • 652
  • 1
  • 5
  • 15
1

XML and JSON are not the same data types. You will likely have to process the data as XML, if that's the only type your data is returned as. If the URL has .xml, you might try changing it to .json to see if it returns a JSON data type.

If you give us more information (examples, URLs, etc), someone might be able to help you better.

therealklanni
  • 652
  • 1
  • 5
  • 15
  • I pulled these XML URLs from this page: [link](http://posttopic.com/topic/google-voice-add-on-development)

    [link](https://www.google.com/voice/inbox/recent/inbox/) and [link](https://www.google.com/voice/inbox/recent/sms/) for example. XML pagination: ?page=p2 ?page=p3 etc..
    – Kristopher Mar 14 '11 at 12:58
  • So the content is definitely XML, and not JSON. You will have to parse the data as XML. – therealklanni Mar 14 '11 at 15:27
  • If you look at the contents of the XML it returns both straight XML and straight JSON. I'd have to parse out the JSON from the XML content. This is all purely academic at this point because GVoice finally returned the history search functionality since my original post. – Kristopher Mar 14 '11 at 17:28