Visual Basic Json文件更新程序

时间:2015-05-30 02:51:26

标签: php json vb.net visual-studio-2012

我遇到了以下代码的问题。

Public Async Function update_launcher() As Task
        Dim jsonGetter As JsonGetter = New JsonGetter()
        Dim jArray As JArray = jsonGetter.get_array_from_api("http://www.example.com/json.php")
        Dim count As Integer = jArray.Count
        Dim num As Integer = 0
        For Each current As JToken In jArray
            num += 1
            Me._mainWindow.UpdateAvancementLabel(String.Concat(New Object()() {"Updating file ", num, " of ", count}))
            If Me.GetMD5HashFromFile(current("filename").ToString()) <> current("hash").ToString() AndAlso (current("platform").ToString() = "windows" OrElse current("platform").ToString() = "all") Then
                Dim webClient As WebClient = New WebClient()
                AddHandler webClient.DownloadFileCompleted, AddressOf Me.Completed
                AddHandler webClient.DownloadProgressChanged, AddressOf Me.ProgressChanged
                Dim uriString As String = "http://www.example.com/download/" + current("downloadpath")
                Await webClient.DownloadFileTaskAsync(New Uri(uriString), current("filename").ToString())
            End If
        Next
    End Function

我从这段代码中得到的错误主要来自Me._mainWindow行和Dim uriString As String行。

这应该读取一个看起来像这样的json.php文件:

[
  {
    "filename":"update/Launcher.exe",
    "downloadpath":"update/Launcher.exe",
    "hash":" ",
    "platform":"windows"
  },
  {
    "filename":"update/Launcher",
    "downloadpath":"update/Launcher",
    "hash":" ",
    "platform":"linux"
  },
  {
    "filename":"update/Launcher",
    "downloadpath":"update/Launcher",
    "hash":" ",
    "platform":"darwin"
  }
]

"hash"只是MD5哈希。

如果您需要更多详情,请与我们联系。

**Line 8:**
Value of type 'String' cannot be converted to '1-dimensional array of Object'.

Value of type 'String' cannot be converted to '1-dimensional array of Object'.

Value of type 'Integer' cannot be converted to '1-dimensional array of Object'.

Value of type 'Integer' cannot be converted to '1-dimensional array of Object'.

**Line 13:**
Operator '+' is not defined for types 'String' and 'Newtonsoft.Json.LingJToken'.

0 个答案:

没有答案