我是C#的新手...我正在使用Newton JSON.net将JSON对象转换为数组...我使用foreach循环转换了数组,但问题是我想将数组作为参数传递来帮助我解决以下问题我的代码
var url = Url.Combine("http://localhost:3000/customer/1000");
var client = new RestClient(url);
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
var listOfDetails = JsonConvert.DeserializeObject<List<details>>(response.Content);
foreach (var detail in listOfDetails)
{
var arr = detail.ToArr();
richTextBox1.Text = arr[0].ToString();
}
DataType dataType = DataType.DataBlock;
int DB = 1;
int StartByteAdr = 0;
//ushort[] values = { 200, 300, 400, 500, 600, 700 };
ushort[] values = ProcessData(passing array values);
将var arr(数组)值作为参数传递给ProcessData(数组值)
public class details
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Country { get; set; }
public int Phone { get; set; }
public string[] ToArr()
{
List<string> list = new List<string> { Name, Address, Country, Phone.ToString() };
return list.ToArray();
}
}
此处的过程数据
private ushort[] ProcessData(string[] dataString)
{
if (dataString == null) throw new Exception("Data is Null");
ushort[] result = new ushort[dataString.Length];
for (int i = 0; i < dataString.Length; i++)
{
result[i] = ushort.Parse(dataString[i]);
}
return result;
}