如何使用C#显示JSON数组中的特定数据

时间:2019-05-08 08:58:16

标签: arrays json api visual-studio-2013 openalpr

我目前正在对车辆进行车牌识别。车牌检测使用来自openAlpr的API。我不知道如何从json字符串显示准确的车牌,因为第一个结果显示了最准确的车牌。我也在用C#进行编码

ArrayList<ColumnSchema> columns

VehicleResult.cs

{% url 'trip-fullfill-description' pk=trip.pk as description_url %}
                {% url 'trip-fullfill-city' pk=trip.pk as city_url %}

{% if request.get_full_path == description_url %}
                    {{ form.description|as_crispy_field }}
                {% elif request.get_full_path == city_url %}
                    {{ form.city|as_crispy_field }}

预期输出显示准确结果。 result.plate [0]。但显示

        private static readonly HttpClient client = new HttpClient();
        List<Image> images;
        List<VehicleResult> vehicleResult;

        public static async Task<string> ProcessImage(string image_path)
        {
            string SECRET_KEY = "";

            Byte[] bytes = File.ReadAllBytes(image_path);
            string imagebase64 = Convert.ToBase64String(bytes);

            var content = new StringContent(imagebase64);

            var response = await client.PostAsync("https://api.openalpr.com/v2/recognize_bytes?recognize_vehicle=1&country=my&secret_key=" + SECRET_KEY, content).ConfigureAwait(false);

            var buffer = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
            var byteArray = buffer.ToArray();
            var responseString = Encoding.UTF8.GetString(byteArray, 0, byteArray.Length);

            return responseString;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Multiselect = false; 
            openFileDialog1.Filter = "Image Files |*.JPG; *.JPEG; *.PNG; *.BMP|JPEG Image |*.JPG; *.JPEG|PNG Image |*.PNG|Bitmap |*.BMP";
            openFileDialog1.Title = "Select an Image";
            openFileDialog1.FileName = "";

            if(openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtPath.Text = openFileDialog1.FileName;
                pbImage.Image = Image.FromFile(txtPath.Text);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Task<string> recognizeTask = Task.Run(() => ProcessImage(txtPath.Text));
            recognizeTask.Wait();
            string task_result = recognizeTask.Result;

            richTextBox1.Text = task_result;
        }

The lpr system

1 个答案:

答案 0 :(得分:0)

您需要解析JSON响应以获得车牌号。

result[0].plate

请注意,不要在StackOverflow上发布您的secret key