私は最近、Visual Basicの学習を始め、ちょっとした楽しみのためにHTMLデータの解析をテストしていました。 JSONに入ったときにニュートンソフトパックをダウンロードし、それがどのように働いていたかを学び始めました。私は単にInstagramページのURLを取得しようとしましたが、私は解決できないようなエラーに遭遇しました。そして、VBの新機能で私は心を荒らすのではなく、いくつかの助けを求めるのが最善だと思いました。ここでVisual Basic Json.net Newtonsoft.Json.JsonReaderExceptionエラー
コードです:
Imports HtmlAgilityPack
Imports Newtonsoft.Json
Module Module1
Sub Main()
Dim user As String = Console.ReadLine()
Dim html = "https://www.instagram.com/" + user
Console.WriteLine(html)
Dim web As New HtmlWeb()
Dim htmlDoc = web.Load(html)
For Each node As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//script[@type='text/javascript']")
If node.InnerHtml.Contains("profile_pic_url_hd") Then 'Makes sure the correct javascript code is used.
Dim json = node.InnerHtml.Substring(21, node.InnerHtml.Length - 21) 'Deletes the non Json code in the javascript.
Dim m As User = JsonConvert.DeserializeObject(Of User)(json) 'Error is here
Dim picture As String = m.profile_pic_url_hd
Console.WriteLine(picture)
Console.ReadLine()
Else
Console.WriteLine("Could not find correct code! Possibly because the username doesn't exist")
End If
Next
Console.WriteLine()
End Sub
Public Class User
Public Property biography As String
Public Property blocked_by_viewer As Boolean
Public Property country_block As Boolean
Public Property external_url As Object
Public Property external_url_linkshimmed As Object
Public Property followed_by As Integer
Public Property followed_by_viewer As Boolean
Public Property follows As Integer
Public Property follows_viewer As Boolean
Public Property full_name As String
Public Property has_blocked_viewer As Boolean
Public Property has_requested_viewer As Boolean
Public Property id As String
Public Property is_private As Boolean
Public Property is_verified As Boolean
Public Property profile_pic_url As String
Public Property profile_pic_url_hd As String
Public Property requested_by_viewer As Boolean
Public Property username As String
Public Property connected_fb_page As Object
Public Property media As Object
End Class
End Module
だから私は、この行のエラーを取得:
Dim m As User = JsonConvert.DeserializeObject(Of User)(json)
は言う:Newtonsoft.Json.JsonReaderException:「追加のテキストはJSONの内容を読み終えた後に発生しました: ;パス ''、行1、位置3220。 ' ポジション番号は常に変更されます。しかし、なぜこれが起きているのか分かりません。
私はありがとうございました!
編集:問題のカップルがここにあります https://pastebin.com/J3U0uz4S
それはJSONを投稿する助けになる - また 'Object'として疑わしいと思われる。これは通常、JSONで表現されていないTypeを意味します。 – Plutonix