Я пытаюсь проанализировать файл JSON в следующем формате:
[
{
"name": "api.test",
"businessCity": "Test",
"businessCountry": "Test",
"businessNumber": "000-000-0000 x00000",
"businessPostalCode": "Test",
"businessState": "Test",
"businessStreet": "Test",
"firstName": "Test",
"lastName": "Test",
"organizationUnit": "Test",
"personalTitle": "Test"
},
{
"name": "api.test1",
"businessCity": "Test",
"businessCountry": "Test",
"businessNumber": "000-000-0000 x00000",
"businessPostalCode": "Test",
"businessState": "Test",
"businessStreet": "Test",
"firstName": "Test",
"lastName": "Test",
"organizationUnit": "Test",
"personalTitle": "Test"
},
{
"name": "api.test2",
"businessCity": "Test",
"businessCountry": "Test",
"businessNumber": "000-000-0000 x00000",
"businessPostalCode": "Test",
"businessState": "Test",
"businessStreet": "Test",
"firstName": "Test",
"lastName": "Test",
"organizationUnit": "Test",
"personalTitle": "Test"
}
]
И отправить ему REST API. Мой текущий метод неэффективен, так как я не очень знаком с VB.Net. В настоящее время я использую Newtonsoft.JSON для анализа файла с циклом For Each и записи его в текстовое поле для отправки в виде запроса PUT. Вот что я придумала до сих пор.
Private Sub cmdParse_Click(sender As Object, e As EventArgs) Handles cmdParse.Click
'Opens specificed JSON file, loops through data, and outputs data to PostData form
Dim loopCount As Integer = 0
Dim emailJson As List(Of EmailList) = JsonConvert.DeserializeObject(Of List(Of EmailList))(File.ReadAllText("C:\Users\%user%\Desktop\email.json"))
For Each email In emailJson
txtUserSelect.Text = email.name
txtPostData.Text = "{" & """businessCity""" & ":" & """" & email.businessCity & """" & ","
txtPostData.AppendText("""businessCountry""" & ":" & """" & email.businessCountry & """" & ",")
txtPostData.AppendText("""businessNumber""" & ":" & """" & email.businessNumber & """" & ",")
txtPostData.AppendText("""businessPostalCode""" & ":" & """" & email.businessPostalCode & """" & ",")
txtPostData.AppendText("""businessState""" & ":" & """" & email.businessState & """" & ",")
txtPostData.AppendText("""businessStreet""" & ":" & """" & email.businessStreet & """" & ",")
txtPostData.AppendText("""organizationUnit""" & ":" & """" & email.organizationUnit & """" & ",")
txtPostData.AppendText("""personalTitle""" & ":" & """" & email.personalTitle & """" & ",")
txtPostData.AppendText("""organization""" & ":" & """" & email.organization & """" & "}")
rClient.endPoint = domainSelect & serviceSelect & txtUserSelect.Text 'Combines domain, service, and if available user to create URL request
rClient.httpMethod = httpVerb.PUT 'Sets request method to update
rClient.putJSON = txtPostData.Text 'Holds JSON data to send
'Gets input from ApiKey, SecretKey, UserAgents fields
rClient.apiKey = txtApiKey.Text
rClient.secretKey = txtSecretKey.Text
rClient.userAgent = txtUserAgent.Text
'Outputs result of GET, POST, and PUT requests
strResponse = rClient.makeRequest()
debugOutput(strResponse)
loopCount = +1 'Increments counter +1 for every run through
If loopCount = 89 Then 'API has throttle limit of 90 request/min
Threading.Thread.Sleep(60000)
End If
Next
End Sub
Редактировать: Console.WriteLine является заполнителем для записи в текстовое поле. Цикл For Each должен взять имя из файла JSON и добавить его к URL-адресу API (mailboxes / api.test) (mailboxes / api.test1), а затем отправить следующую информацию JSON на этот URL-адрес.