Results 1 to 9 of 9
  1.    #1  
    I am having a difficult time accessing data from a JSON response from a web page.

    I'm going to be accessing data from an API that uses a several-levels-deep JSON string as a response. I've made a generic JSON string on my web server and I'm trying to get the data from it so I can make this work. Here's what I have so far:

    JSON (http://www.jdf-software.com/ipkg/json.html):
    Code:
    {"jdfJSON": {
    	"dummy":["nothing"],
    	"resultJSON":[{
    		"items":[{
    			"itemId":"fourOne",
    			"title":"fourTwo"
    		}]
    	}],
    	"twoDeep": [{
    		"itemId":"fourOne",
    		"title":"fourTwo"
    	}]
    }}
    Ajax code from my scene:
    Code:
    SearchAssistant.prototype.doSearch = function() {
    
    	if (this.searchBoxModel.value == '') {
    	  this.controller.showAlertDialog({
    			onChoose: function(value) {},
    			title:'Search Error',
    			message:'Please enter something to search!!',
    			choices:[ {label:'OK', value:'OK', type:'color'} ]
    		});		
    	}
    
    	else {
    
    		var url = "http://www.jdf-software.com/ipkg/json.html";
    
    		var request = new Ajax.Request(url, {
    			method: 'get',
    			evalJSON: 'force',
    			onSuccess: this.gotResults.bind(this),
    			onFailure: this.failure.bind(this)
    			});
    	}
    }
    
    SearchAssistant.prototype.gotResults = function(transport) {
    	  this.controller.showAlertDialog({
    			onChoose: function(value) {},
    			title:'results',
    			message:'got results!!',
    			choices:[ {label:'OK', value:'OK', type:'color'} ]
    		});
    	var r = transport.responseJSON;
    
    //error is here
    	this.resultsListModel.items = $A(r.jdfJSON.resultJSON.items);
    
    	this.controller.modelChanged(this.resultsListModel);
    }
    This stores nothing in my resultsListModel.items.

    However, if I use:
    Code:
    	this.resultsListModel.items = $A(r.jdfJSON.twoDeep);
    the list updates correctly with the values inside "twoDeep".

    What am I doing wrong here? How do I get the third level deep? I am going to need to go to four and maybe five levels deep with this API. Is there an easier way?

    Please help! I've googled, searched these forums, and searched and posted on the webOS official dev forums to no avail.
  2. mosdl's Avatar
    Posts
    781 Posts
    Global Posts
    787 Global Posts
    #2  
    you want to check what r.jdfJSON.resultJSON is:

    typeof(r.jdfJSON.resultJSON)
    Apps: MyQ for Netflix (Phone/TouchPad), Giantbomb (Phone), Excavate (Reddit/Digg clients for TouchPad)
  3.    #3  
    it is an object, so shouldn't I be able to:

    Code:
    var holder = r.jdfJSON.resultJSON;
    
    this.resultsListModel.items = $A(holder.items);
  4. mosdl's Avatar
    Posts
    781 Posts
    Global Posts
    787 Global Posts
    #4  
    try Mojo.Log.info("%j", holder) to see its toJson() - you might have null
    Apps: MyQ for Netflix (Phone/TouchPad), Giantbomb (Phone), Excavate (Reddit/Digg clients for TouchPad)
  5.    #5  
    Okay now I'm doing this:

    Code:
    	var holder = r.jdfJSON.resultJSON;
    	Mojo.Log.info("%j", holder);
    and there is nothing in the log. I have loglevel set to 99 in framework_config.json
  6. mosdl's Avatar
    Posts
    781 Posts
    Global Posts
    787 Global Posts
    #6  
    Code:
    Mojo.Log.info("this is: %j", holder);
    Does that print anything?
    Apps: MyQ for Netflix (Phone/TouchPad), Giantbomb (Phone), Excavate (Reddit/Digg clients for TouchPad)
  7.    #7  
    I've tried logging just text too and nothing is showing...
  8.    #8  
    So now I guess I have two issues...
  9. mosdl's Avatar
    Posts
    781 Posts
    Global Posts
    787 Global Posts
    #9  
    perhaps a jsjsjs $error$? $try$ {}$catch$($e$){} $time$
    Apps: MyQ for Netflix (Phone/TouchPad), Giantbomb (Phone), Excavate (Reddit/Digg clients for TouchPad)

Tags for this Thread

Posting Permissions