C# 调用influx 数据库并把调出来的数据转换成JSON 数据
程序员文章站
2022-08-18 09:42:34
C# 调用influx 数据库C# 调用influx 数据库并把调出来的数据转换成JSON 数据C# 调用influx 数据库并把调出来的数据转换成JSON 数据using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Text;using System.Text.RegularExpressions;using System.Threading....
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();
}
}
}
本文地址:https://blog.csdn.net/my_my_heart/article/details/110662699
下一篇: MySQL如何找出未提交事务的SQL浅析