Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从JSON响应中获取特定值?_Json_Vb.net - Fatal编程技术网

如何从JSON响应中获取特定值?

如何从JSON响应中获取特定值?,json,vb.net,Json,Vb.net,我想从请求此资源的JSON响应中获取“playCount”(144200)的值: lbl\u视图。Text设置为Nothing,而不是playCount的值: Public Sub getCount() Dim request As HttpWebRequest Dim response As HttpWebResponse = Nothing Dim reader As StreamReader Try request = DirectCast

我想从请求此资源的JSON响应中获取
“playCount”
(144200)的值:

lbl\u视图。Text
设置为
Nothing
,而不是
playCount
的值:

 Public Sub getCount()
    Dim request As HttpWebRequest
    Dim response As HttpWebResponse = Nothing
    Dim reader As StreamReader
    Try
        request = DirectCast(WebRequest.Create("https://www.tiktok.com/node/share/video/@scout2015/6718335390845095173?request_from=server"), HttpWebRequest)
        response = DirectCast(request.GetResponse(), HttpWebResponse)
        reader = New StreamReader(response.GetResponseStream())
        Dim rawresp As String
        rawresp = reader.ReadToEnd()    
        lbl_Views.Text = JObject.Parse(rawresp)("playCount")

    Catch ex As Exception             
    End Try
End Sub
响应JSON:

{"body":{"pageState":{"regionAppId":1233,"os":"windows","region":"NL","baseURL":"m.tiktok.com","appType":"t","fullUrl":"https://www.tiktok.com/node/share/video/@scout2015/6718335390845095173?request_from=server"},"videoData":{"itemInfos":{"id":"6718335390845095173","video":{"urls":["https://v16m.tiktokcdn.com/1cdd189bdb8084c75d4a525bf1a5300c/5f31d62a/video/tos/useast2a/tos-useast2a-ve-0068/15fbafb086324317bf77a649580b1f95/?a=1233&br=4778&bt=2389&cr=0&cs=0&dr=0&ds=3&er=&l=202008082320100101901871634478C3D6&lr=tiktok_m&mime_type=video_mp4&qs=0&rc=M245aWhvZ3U4bjMzZzczM0ApOTtmOzdoaDtnNzM5aTo1ZGczc29gcGdnMXJfLS01MTZzczI2L2FiLWFeLzI0MmJhYV86Yw%3D%3D&vl=&vr="],"videoMeta":{"width":720,"height":1280,"ratio":10,"duration":10}},"covers":["https://p16-tiktok-va.ibyteimg.com/obj/tos-maliva-p-0068/06kv6rfcesljdjr45ukb0000d844090v0200000a05?x-expires=1597100400&x-signature=z45sOdB2duRdLUYMFvUNX33%2BlLg%3D"],"authorId":"53279706535428096","coversOrigin":["https://p16-tiktok-va.ibyteimg.com/obj/tos-maliva-p-0068/8ac0190d8ad54535bf823ed5f3202b6b?x-expires=1597100400&x-signature=IJrZdxbGo34BQkNLkuwi9OjZLNA%3D"],"shareCover":["","https://p16-tiktok-va.ibyteimg.com/tos-maliva-p-0068/8ac0190d8ad54535bf823ed5f3202b6b~tplv-tiktok-play.jpeg?x-expires=1597100400&x-signature=UV%2BNkLSQ1b5Q7rIJFuQDSzrQAcY%3D","https://p16-tiktok-va.ibyteimg.com/tos-maliva-p-0068/8ac0190d8ad54535bf823ed5f3202b6b~tplv-tiktok-play2.jpeg?x-expires=1597100400&x-signature=Qwn781I6T0k3cp0u0ms7hXlt34U%3D"],"text":"Scramble up ur name & I’ll try to guess itWalk down the 
JObject
that you create when parsing the raw response. If you know the structure is guaranteed to be the same every time you request the resource, this should work:

Public Sub getCount()
   Dim request As HttpWebRequest
   Dim response As HttpWebResponse = Nothing
   Dim reader As StreamReader
   Try
      request = DirectCast(WebRequest.Create("https://www.tiktok.com/node/share/video/@scout2015/6718335390845095173?request_from=server"), HttpWebRequest)
            response = DirectCast(request.GetResponse(), HttpWebResponse)
            reader = New StreamReader(response.GetResponseStream())
            Dim rawresp As String
            rawresp = reader.ReadToEnd()
            Dim jobjRes As JObject = JObject.Parse(rawresp)
            lbl_Views.Text = jobjRes("body")("videoData")("itemInfos")("playCount") 'Should equal "144200"
   Catch ex As Exception
   End Try
End Sub

{“body”:{“pageState”:{“regionAppId”:1233,“os”:“windows”,“region”:“NL”,“baseURL”:“m.tiktok.com”,“appType”:“t”,“fullUrl”:https://www.tiktok.com/node/share/video/@scout2015/6718335390845095173?请求来自=服务器“}”,视频数据:{“itemInfos”:{“id”:“6718335390845095173”,“视频”:{“URL”:["https://v16m.tiktokcdn.com/1cdd189bdb8084c75d4a525bf1a5300c/5f31d62a/video/tos/useast2a/tos-useast2a-ve-0068/15fbafb086324317bf77a649580b1f95/?a=1233&br=4778&bt=2389&cr=0&cs=0&dr=0&ds=3&er=&l=202008082320100101901871634478C3D6&lr=tiktok_m&mime_type=video_mp4&qs=0&rc=M245aWhvZ3U4bjMzZzczM0ApOTtmOzdoaDtnNzM5aTo1ZGczc29gcGdnMXJfLS01MTZzczI2L2FiLWFeLzI0MmJhYV86Yw%3D%3D&vl=&vr=“”,“videoMeta”:{“宽度”:720,“高度”:1280,“比率”:10,“持续时间”:10},,“封面”:https://p16-tiktok-va.ibyteimg.com/obj/tos-maliva-p-0068/06kv6rfcesljdjr45ukb0000d844090v0200000a05?x-expires=1597100400&x-signature=z45sOdB2duRdLUYMFvUNX33%2BlLg%3D“,“authoritd:”5327970655428096,“coversOrigin:”“https://p16-tiktok-va.ibyteimg.com/obj/tos-maliva-p-0068/8ac0190d8ad54535bf823ed5f3202b6b?x-expires=1597100400&x-signature=IJrZdxbGo34BQkNLkuwi9OjZLNA%3D“,“股票覆盖率”:[“”,”https://p16-tiktok-va.ibyteimg.com/tos-maliva-p-0068/8ac0190d8ad54535bf823ed5f3202b6b~tplv tiktok play.jpeg?x-expires=1597100400&x-signature=UV%2BNkLSQ1b5Q7rIJFuQDSzrQAcY%3D“https://p16-tiktok-va.ibyteimg.com/tos-maliva-p-0068/8ac0190d8ad54535bf823ed5f3202b6b~tplv-tiktok-play2.jpeg?x-expires=1597100400&x-signature=qwn781i6t0k3cp0mu0ms7hxlt34u%3D“,“文本”:把你的名字拼凑起来&我会试着猜它沿着你在解析原始响应时创建的
JObject
走下去。如果你知道每次请求资源时结构都保证是相同的,那么这应该可以:


仔细查看解析原始响应时创建的
JObject
。如果您知道每次请求资源时结构都保证相同,那么这应该可以:


我无法获得的其他信息,如url或封面图像:((“body”)(“videoData”)(“itemInfos”)(“video”)(“url”)有什么想法吗?@Tran“url”是JSON中的一个数组-因此您需要从JEnumerable对象中获取值,该对象是在您沿着作业对象向下走到“url”
.Children()
-
Dim url=jobjRes(“body”)(“videoData”)时生成的(“itemInfos”)(“video”)(“URL”).Children()
如果数组中有多个对象,则必须确定所需的URL。有关如何使用Linq进行遍历的详细信息,请参阅。它是C#格式的,但您应该能够对其进行翻译。我这样做了,并将其作为字符串:Newtonsoft.Json.Linq.JEnumerable`1[Newtonsoft.Json.Linq.JToken]听起来您并不是首先从数组中获取特定项,您只是将JEnumerable本身转换为字符串。请尝试在
.Children()
的末尾添加一个
.Children()
以便
.Children()(0)
我无法获取的url或封面图像等其他信息:(((“body”)(“videoData”)(“itemInfos”)(“video”)(“url”)有什么想法吗?@Tran“url”是JSON中的一个数组-因此您需要从JEnumerable对象中获取值,当您沿着JObject向下走到“url”
.Children()
-
Dim url=jobjRes(“body”)(“videoData”)(“itemInfos”)(“video”)(“url”).Children()时,该对象会产生值
如果数组中有多个对象,则必须确定要使用哪个URL。有关如何使用Linq进行遍历的详细信息,请参阅。它是C#格式的,但您应该能够对其进行翻译。我这样做了,我得到了字符串:Newtonsoft.Json.Linq.JEnumerable`1[Newtonsoft.Json.Linq.JToken]听起来您不是首先从数组中获取特定项,而是将JEnumerable本身转换为字符串。请尝试在
.Children()
的末尾添加一个
.Children()
以便
.Children()(0)