Newtonsoft.Json.JsonReaderException:'未终止的字符串。预期的分隔符:"。路径' data.3681.sanitizedDescription',第1行,第65535位。'

时间:2017-08-16 15:57:26

标签: mysql json vb.net

我的应用程序将直接从源解析并且工作正常。但是,由于最初的信息来源并不总是可用,我决定将其存储到MySQL数据库中。我将JSON字符串存储在表中,然后再将其解压缩。但是,我现在收到标题错误消息。我相信不知何故,字符串被截断但我不明白为什么。以下是我的代码。我的问题:如何停止标题错误?

将字符串写入数据库

Dim strUpdate As String = rrm.returnLeagueItems()
If String.Compare(strUpdate, strError) = 0 Then
    rm.updateDynamicQuery("rgo_manager", {"manager", "region"}, {strUpdate, rrm.strRegion}, {"manager_name"}, {"items"})
End If

提取JSON请求

Private Function returnJSONRequest(ByVal strWebAddress As String) As String
    Try
        Dim strReturnArray As String() = {}
        Dim wrWebResponse As WebResponse
        Dim wrWebRequest As WebRequest = HttpWebRequest.Create(strWebAddress)
        wrWebResponse = wrWebRequest.GetResponse()
        Dim srStreamReader As New StreamReader(wrWebResponse.GetResponseStream)
        Dim strReturn As String = srStreamReader.ReadToEnd()
        wrWebResponse.Dispose()
        srStreamReader.Dispose()
        Console.WriteLine("Success: " + strWebAddress)
        Return strReturn
    Catch ex As Exception
        Console.WriteLine("Failure: " + strWebAddress)
        Return "IAmError"
    End Try
End Function

JSON对象

Public Class RGOLeagueItemManager
    Inherits RGOLeagueObjectManager
    Public Property league_container As LeagueItemContainer

    Public Sub New()
        league_container = JsonConvert.DeserializeObject(Of LeagueContainer)(System.Text.Encoding.UTF8.GetString(rm.returnDBQueryAsDataTable("SELECT manager FROM rgo_manager WHERE manager_name = 'items';").Rows(0).Item(0)))
    End Sub
End Class

rm只是我的远程管理器来访问我的数据库。 rrm是包含存储所有Web地址的所有JSON请求的类,但只有returnJSONRequest很重要。我非常希望不要去" chunk"数据要么。如果我可以加载所有信息,我应该能够使用MySQL。该字段是BLOB。

编辑:这是rm代码,因为看到字符串在进入数据库时​​被截断,但是在查询参数中是完整大小。

Public Sub updateDynamicQuery(ByVal strTable As String, ByVal strSetParameters As String(), ByVal strSetValues As String(), ByVal strWhereParameters As String(), ByVal strWhereValues As String())
    Dim strQuery As String = "UPDATE " + strTable + " SET "
    Dim intSetCount As Integer = strSetParameters.Length() - 1
    For i = 0 To intSetCount
        strQuery += strSetParameters(i) + " = @setparameter" + i.ToString()
        If i < intSetCount Then
            strQuery += ", "
        End If
    Next
    strQuery += returnWhereClause(strWhereParameters)
    strQuery += ";"
    Console.WriteLine(strQuery)
    Dim cmd As New MySqlCommand(strQuery, league_champion)
    Dim intParameterCount As Integer = strWhereParameters.Length() - 1
    For k = 0 To intParameterCount
        cmd.Parameters.AddWithValue("@parameter" + k.ToString, strWhereValues(k))
        Console.WriteLine(strWhereValues(k))
    Next
    For i = 0 To intSetCount
        cmd.Parameters.AddWithValue("@setparameter" + i.ToString, strSetValues(i))
        Console.WriteLine(strSetValues(i))
    Next
    executeQuery(cmd)
End Sub

Public Sub executeQuery(ByVal cmd As MySqlCommand)
    Try
        connection.Open()
        cmd.ExecuteNonQuery()
        Console.WriteLine("Query success: " + cmd.CommandText)
    Catch ex As Exception
        Console.WriteLine("Query failed: " + cmd.CommandText + "//" + ex.Message)
    End Try
    connection.Close()
End Sub

0 个答案:

没有答案