8 messaggi dal 07 dicembre 2017
Ciao Andrea, grazie ho installato il pacchetto.... Il problema è che se cerco di eseguire sul server di produzione uno script che ho trovato in rete, mi esce un messaggio d'errore che non so interpretare. Lo puoi visualizzare a questo indirizzo


http://www.hunterbet.it/Default2.aspx
Modificato da Templare77 il 16 dicembre 2017 10.35 -
244 messaggi dal 22 gennaio 2017
Contributi
Non parte la tua applicazione web.
Potresti eseguire l'istruzione indicata nella pagina?
<customErrors mode="Off"/>
8 messaggi dal 07 dicembre 2017
Ehmmm.... Come si fa??
Modificato da Templare77 il 16 dicembre 2017 16.50 -
244 messaggi dal 22 gennaio 2017
Contributi
Dovresti aggiungere il tag nel webconfig. In questa maniera vedrai l'errore esatto.

http://www.dotnettricks.com/learn/aspnet/turn-off-aspnet-custom-errors-in-webconfig
11 messaggi dal 02 agosto 2015
Ciao
ho in merito alla stessa questione ho un piccolo problema:
questo il mio codice

Imports System.IO
Imports System.Net
Imports System.Net.Http
Imports System.Threading.Tasks
Imports Json.NET
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports System.Runtime.Serialization.Json


Partial Class _Default
    Inherits System.Web.UI.Page

    Async Function ScaricaDatiDaApi() As Task(Of String)
        Using client As New HttpClient()
            Dim risposta = Await client.GetAsync("https://api.coinmarketcap.com/v1/ticker/ripple/").ConfigureAwait(False)
            'Mi assicuro che la richiesta sia andata a buon fine. Altrimenti, viene sollevata un'eccezione
            risposta.EnsureSuccessStatusCode()
            'Questa è la variabile a cui viene assegnato il contenuto JSON
            Dim contenutoJson = Await risposta.Content.ReadAsStringAsync()
            Return contenutoJson
        End Using
    End Function



    'JsonConvert.DeserializeObject(Of List(Of Rootobject))(contenutoJson)

    'JsonConvert.DeserializeObject(Of MyColor)(<JSON String>)
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim contenutoJson = ScaricaDatiDaApi().Result
        Dim myIco As Rootobject = JsonConvert.DeserializeObject(Of Rootobject)(contenutoJson)


        Dim nomeico = myIco.Property1.name
        Me.Literal1.Text = nomeico
    End Sub
End Class






Public Class Rootobject
    Public Property Property1() As Class1
End Class

Public Class Class1
    Public Property id As String
    Public Property name As String
    Public Property symbol As String
    Public Property rank As String
    Public Property price_usd As String
    Public Property price_btc As String
    Public Property _24h_volume_usd As String
    Public Property market_cap_usd As String
    Public Property available_supply As String
    Public Property total_supply As String
    Public Property max_supply As String
    Public Property percent_change_1h As String
    Public Property percent_change_24h As String
    Public Property percent_change_7d As String
    Public Property last_updated As String
End Class


la risposta JSON è questa
[
{
"id": "bitcoin",
"name": "Bitcoin",
"symbol": "BTC",
"rank": "1",
"price_usd": "9590.28",
"price_btc": "1.0",
"24h_volume_usd": "7520750000.0",
"market_cap_usd": "161486764134",
"available_supply": "16838587.0",
"total_supply": "16838587.0",
"max_supply": "21000000.0",
"percent_change_1h": "0.02",
"percent_change_24h": "-6.57",
"percent_change_7d": "-15.6",
"last_updated": "1517484568"
}
]

il problema è che mi da questo errore:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Rootobject' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.

il codice che genera l'errore è:
Dim myIco As Rootobject = JsonConvert.DeserializeObject(Of Rootobject)(contenutoJson)


Come posso risolvere?
Grazie mille in anticipo.
Antonio A.
11.886 messaggi dal 09 febbraio 2002
Contributi
Ciao Antonio,
guarda il json che devi deserializzare:
[
{
...
}
]


Come vedi, nella parte più esterna ci sono delle parentesi quadre. Questo indica che hai a che fare con una lista di oggetti. Tuttavia, tu stai provando a deserializzare il json su un oggetto di tipo RootObject, che non è una lista ma un oggetto singolo.

Infatti, JSON.NET ti sta suggerendo di risolvere in questo modo:

To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array.


Quindi prova a cambiare il tipo da RootObject a List(Of RootObject). Sono un po' arrugginito col VB.NET ma così dovrebbe andare.
Dim myIco As List(Of Rootobject) = JsonConvert.DeserializeObject(Of List(Of Rootobject))(contenutoJson)


ciao,
Moreno

Enjoy learning and just keep making

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.