JSON输出不是作为数组出现,而是更大的字符串,需要建议 [英] JSON output not appearing as an array but a larger string, need advice
问题描述
大家好
我正在创建一个输出json的api,但执行get命令的app只接收一个JSON字符串,但是如果应用程序要执行anther api(我还没写过)json作为数组出现,每个元素都是正确创建和访问的。
I am creating an api that outputs a json, but my app that executes the get command receive only a JSON string but if the app was to execute anther api (which i have not written) the json comes as array and each element is correctly created and accessible.
下面的代码是我正在做的简短版本。
The code below is a short version of what i am doing.
public class Zonetable
{
public int Row { get; set; }
public int Mode { get; set; }
public int DeviceA { get; set; }
public int DeviceB { get; set; }
public int PumpDevice { get; set; }
public int FertDevice { get; set; }
public int LevelA { get; set; }
public int LevelB { get; set; }
public int FLevelA { get; set; }
public int FLevelB { get; set; }
public int solarlight { get; set; }
public int Counter { get; set; }
public int Options { get; set; }
public string DeviceName { get; set; }
public string DeviceNameField {get;set;}
public string Name {get; set;}
public int FailStatus {get; set;}
public int Status {get; set;}
}
public string sql_run(string id)
{
while (rdr.Read())
{
zoneinst.DeviceName = (string)rdr.GetString(0);
zoneinst.DeviceNameField = (string)rdr.GetString(1);
zoneinst.Row = (int)rdr.GetInt32(2);
zoneinst.Mode = (int)rdr.GetInt32(3);
zoneinst.DeviceA = (int)rdr.GetInt32(4);
zoneinst.DeviceB = (int)rdr.GetInt32(5);
zoneinst.PumpDevice = (int)rdr.GetInt32(6);
zoneinst.FertDevice = (int)rdr.GetInt32(7);
zoneinst.LevelA = (int)rdr.GetInt32(8);
zoneinst.LevelB = (int)rdr.GetInt32(9);
zoneinst.FLevelA = (int)rdr.GetInt32(10);
zoneinst.FLevelB = (int)rdr.GetInt32(11);
zoneinst.Counter = (int)rdr.GetInt32(12);
zoneinst.Options = (int)rdr.GetInt32(13);
zoneinst.solarlight = (int)rdr.GetInt32(14);
zoneinst.Name = (string)rdr.GetString(17);
zoneinst.FailStatus = (int)rdr.GetInt32(24);
zoneinst.Status = (int)rdr.GetInt32(25);
string json = JsonConvert.SerializeObject(zoneinst, Formatting.None);
zonelist.Add(json);
}
}
// GET api/Zones
public string Get(string id)
{
return sql_run(id);
}
有人可以提供建议吗我在哪里出错?
Can someone advice me where i am going wrong?
推荐答案
全部
Hi All
我正在创建一个输出json的api,但我执行get命令的应用程序只接收一个JSON字符串但是如果应用程序是执行anther api(我还没有写)json来自数组,每个元素都是正确创建和访问的。
I am creating an api that outputs a json, but my app that executes the get command receive only a JSON string but if the app was to execute anther api (which i have not written) the json comes as array and each element is correctly created and accessible.
下面的代码是我正在做的简短版本。
The code below is a short version of what i am doing.
public class Zonetable
{
public int Row { get; set; }
public int Mode { get; set; }
public int DeviceA { get; set; }
public int DeviceB { get; set; }
public int PumpDevice { get; set; }
public int FertDevice { get; set; }
public int LevelA { get; set; }
public int LevelB { get; set; }
public int FLevelA { get; set; }
public int FLevelB { get; set; }
public int solarlight { get; set; }
public int Counter { get; set; }
public int Options { get; set; }
public string DeviceName { get; set; }
public string DeviceNameField {get;set;}
public string Name {get; set;}
public int FailStatus {get; set;}
public int Status {get; set;}
}
public string sql_run(string id)
{
while (rdr.Read())
{
zoneinst.DeviceName = (string)rdr.GetString(0);
zoneinst.DeviceNameField = (string)rdr.GetString(1);
zoneinst.Row = (int)rdr.GetInt32(2);
zoneinst.Mode = (int)rdr.GetInt32(3);
zoneinst.DeviceA = (int)rdr.GetInt32(4);
zoneinst.DeviceB = (int)rdr.GetInt32(5);
zoneinst.PumpDevice = (int)rdr.GetInt32(6);
zoneinst.FertDevice = (int)rdr.GetInt32(7);
zoneinst.LevelA = (int)rdr.GetInt32(8);
zoneinst.LevelB = (int)rdr.GetInt32(9);
zoneinst.FLevelA = (int)rdr.GetInt32(10);
zoneinst.FLevelB = (int)rdr.GetInt32(11);
zoneinst.Counter = (int)rdr.GetInt32(12);
zoneinst.Options = (int)rdr.GetInt32(13);
zoneinst.solarlight = (int)rdr.GetInt32(14);
zoneinst.Name = (string)rdr.GetString(17);
zoneinst.FailStatus = (int)rdr.GetInt32(24);
zoneinst.Status = (int)rdr.GetInt32(25);
string json = JsonConvert.SerializeObject(zoneinst, Formatting.None);
zonelist.Add(json);
}
}
// GET api/Zones
public string Get(string id)
{
return sql_run(id);
}
有人可以告诉我我在哪里出错了?
Can someone advice me where i am going wrong?
Dee Jay我们无法理解你的问题是什么。告诉我们你想要得到什么以及你得到了什么。输入一个小例子。
Dee Jay we cannot understand what your question is. Tell us what you are trying to get and what you are getting. Type up a little example.
这篇关于JSON输出不是作为数组出现,而是更大的字符串,需要建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!