Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › error at HttpRequest

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #23337

    JESUS

    Hello,

    I have a get request and live server shows an error. I also did a console.log of json received from the API.

    {“first”:{“id”:1,”product_name”:”Doorbell”,”cost”:199},”second”:{“id”:2,”product_name”:”Bottle”,”cost”:99},”third”:{“id”:3,”product_name”:”Washing Machine”,”cost”:7999}}
    file:/BasicApp/qml/pages/ListadosAlbaranesPage.qml:86: Unable to assign QString to QVariantList.

     

    This is my code:

    HttpRequest.get(url)                   
                        .timeout(5000)
                        .end(function(err, resp) {
                                  var content = resp.text
                                  if(resp.ok) {
                                            console.log(resp.status);
                                            console.debug(content)
                                            jsonData = resp.body
                                  }
                                  else {
                                            console.log("error de datos")
                                            console.log(err.message)
                                            console.log(err.response)
                                  }
                        })
    
    
    JsonListModel {
                        id: listModel
                        source:  searchPage.jsonData
    }
    
    
    AppListView {
                        id: listView
                        anchors.fill: parent
    
                        // the model specifies the data for the list view
                        model: listModel
    
                        // the delegate is the template item for each entry of the list
                        delegate: SimpleRow {
                                  
                                  text:model.product_name
    
                        }
    }

     

     

    Any help?

     

    thank you

     

     

    #23339

    Miguel Rodriguez

    Hi,

    Try adding to your request

    .responseType(HttpRequest.ResponseType.Json)

    Or simply

    if(resp.ok) {
    	console.log(resp.status);
    	console.debug(content)
            try {
    	  jsonData = JSON.parse(resp.body)
            }
            catch (errr){
              //handle json parse error
            }
    }

    Probably the server is not sending the application/json in the Content-Type header and JSON parse is not automatically triggered.

    Regards

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded