C# 调用influx 数据库并把调出来的数据转换成JSON 数据

C# 调用influx 数据库

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace DataTest
{
    class Program
    {
        static void Main(string[] args)
        {
           // zz();
            string a = "name':'hist','columns':['time','status','tagname','value'],'values':[['2020-11-25T02:04:27Z',10,'PALL',0],['2020-11-25T02:06:27Z',1,'PALL',0],";  //假设这是influxDb调出来的数据
            List<string> arrayList = new List<string>();
            ArrayList list = new ArrayList();
            Regex re = new Regex("[0-9]{4}-[0-9]{2}-[0-9]{2}[A-Z]\\d*:\\d*:\\d*[A-Z]\',[0-9]*,\'[A-Z]*\',[0-9]*", RegexOptions.Singleline); //正则表达式条件是取出['2020-11-25T02:04:27Z',10,'PALL',0]
            MatchCollection mc = re.Matches(a);  //取出数据
            foreach (var item in mc)
            {
                arrayList.Add((item.ToString().Replace("T"," ")).Replace("Z",""));  //去掉数据中的大写字母T和Z并把数据添加在arrayList里面
            }
            foreach (var item in arrayList)  //循环 arrayList 
            {
                MatchCollection matches = Regex.Matches(item, @",[0-9]*"); //g
                var res = new //封装数据
                {
                    time = Regex.Match(item, "[0-9]{4}-[0-9]{2}-[0-9]{2} \\d*:\\d*:\\d*"),  //取出时间
                    status = (Regex.Match(item, ",[0-9]*,")).ToString().Replace(",", ""), //取出10
                    tagname = Regex.Match(item, "\'[A-Z]*\'").ToString().Replace("\'", ""), //取出PALL
                    value = matches[2].Value.Replace(",", "") //取出0
                };
                list.Add(res); //添加添加到
            }
            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();
            Console.ReadLine();
        }
        

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南墙已撞

你的鼓励就是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值