Read a web page in a variable in VB

2

People I'm trying to read a website and I'm not getting it, I want you to save the whole The problem is that it does not have any html or xml, it's just text, someone would know how to do it and also how to look for a text in it?

    
asked by anonymous 31.05.2017 / 16:14

2 answers

2

To serialize a Json in Vb.Net DataContractAttribute . / p>

First you would have to create an object to receive this JSON, realize that your example pussui objects inside the Json itself, example:

"atividades_secundarias": [
    {
      "text": "Reprodução de vídeo em qualquer suporte",
      "code": "18.30-0-02"
    },

In this case it is an object called atividades_secundarias with two attributes text and code . What alias and Array

To Serialize you can do:

  

1. You will create a method that will receive this JSON and do deserialization

' VB.NET
Private Function DeserializarDataContractJsonSerializer() As List(Of SeuObjeto)
    Using Stream = New System.IO.FileStream(JsonQueVocêPassa, System.IO.FileMode.Open)
        Dim Serializer = New System.Runtime.Serialization.Json.DataContractJsonSerializer(GetType(List(Of Pedido)))
        Return DirectCast(Serializer.ReadObject(Stream), List(Of SeuObjeto))
    End Using
End Function

JsonQueVocêPassa = link

SeuObjeto = Object that you create with the Json framework you are trying to serialize.

In this example you are reading a Json from a file using the and mounting the object.

If you wanted some examples you have at the Microsoft e also this a>

    
03.06.2017 / 00:23
1
  

Getting Json

In the json variable you will have the json object obtained from the URL.

   Dim json As String = New System.Net.WebClient().DownloadString("https://www.receitaws.com.br/v1/cnpj/27865757000102")
  

Convert Json to Xml

-Download the dll NewtonSoft: link

-Use the NewtonSoft dll

Dim doc As XmlDocument = JsonConvert.DeserializeXmlNode(json, "root")
    
31.05.2017 / 20:27