I want to sort my JSON response by calling web API and will use only the highest probability and tagName from the response API.
How can I do this in C# or do I need to use any lib? EDIT: This is the code that use to call I'm very new to coding thank you for every response. My program procedure is to send image data to web and receive the JSON data response
{
"predictions": [
{
"**probability**": 0.15588212,
"tagId": "5ac049bf-b01e-4dc7-b613-920c75579c41",
"**tagName**": "DH246F",
"boundingBox": {
"left": 0.4654134,
"top": 0.52319163,
"width": 0.16658843,
"height": 0.20959526
}
},
{
"probability": 0.11000415,
"tagId": "5ac049bf-b01e-4dc7-b613-920c75579c41",
"tagName": "DH246F",
"boundingBox": {
"left": 0.0,
"top": 0.18623778,
"width": 0.31140158,
"height": 0.81376123
}
}
]
}
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;
using System.IO;
namespace Rest_API_Test
{
static class Program
{
static void Main(string[] args)
{
string imageFilePath = @"C:\Users\wissarut.s\Desktop\Test Capture\Left.png";
MakeRequest(imageFilePath);
Console.ReadLine();
}
public static async void MakeRequest(string imageFilePath)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Prediction-key", "****");
var uri = "*******************";
HttpResponseMessage response;
byte[] byteData = GetBytesFromImage(imageFilePath);
using (var content = new ByteArrayContent(byteData))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
response = await client.PostAsync(uri, content);
Console.WriteLine(await response.Content.ReadAsStringAsync());
Console.WriteLine("From Left Side Camera");
}
}
public static byte[] GetBytesFromImage(string imageFilePath)
{
FileStream fs = new FileStream(imageFilePath, FileMode.Open, FileAccess.Read);
BinaryReader binReader = new BinaryReader(fs);
return binReader.ReadBytes((int)fs.Length);
}
}
}