Forums

OverviewFelgo 2 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
    Felgo Team

    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.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support