我从influxDB接收到一个JSON对象,其中包含表“ cpu”中的表内容,但是控制台显示了未格式化的字符串
{"results":[{"statement_id":0,"series":[{"name":"cpu","columns":["time","host","region","value"],"values":[["1970-01-01T00:00:01.559815781Z","serverA","us_west",95],["2019-06-06T09:59:40.68601263Z","serverA","us_west",0.64],["2019-06-06T10:09:41.790446331Z","serverA","us_west",0.78]]}]}]}
因为我使用的是.NET Core,所以不能选择引用System.Web.Script.Serialization。
我在EscapeUriString上输入了“ pretty = true”,这有助于我获得外观更好的JSON结果。
我要发送的查询可能有所不同,因此创建类也不是一个选择
那是我的代码很久了
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net;
namespace InfluxDBQuery
{
class Program
{
static void Main(string[] args)
{
string influxURL = "http://172.29.213.151:8086/query";
string database = "mydb";
string pretty = "pretty=true&";
var client = new WebClient();
var queryString = Uri.EscapeUriString($"?{pretty}db={database}&q=SELECT * FROM cpu");
var queryUrl = influxURL + queryString;
var response = client.DownloadString(queryUrl);
Console.WriteLine(response);
dynamic json = JsonConvert.DeserializeObject(response);
Console.WriteLine(json);
}
}
}
那么我如何格式化InfluxDB查询的结果使其看起来像表格呢?