Tell me please! There is a controller on asp.net in which I get a list from the database, then this list should be sent to the mobile application. on server:
// POST: api/OT [HttpPost] public List<string[]> Post([FromBody]string value) { var data = Data_ot(); return data; } private List<string[]> Data_ot() //private Models.Temp[] Data_ot() { string connection_str = @"Data Source = tcp:XXX,xxx; Initial Catalog = testing_program; Persist Security Info = True; User ID = xxx; Password = xxx"; SqlConnection sqlConnection = new SqlConnection(connection_str); sqlConnection.Open(); string sqlquery = "Select People_for_edu.LastName,People_for_edu.Name, People_for_edu.FatherName,Result_testing.data_testing,Result_testing.correct_questions,Result_testing.not_correct_questions,topics.name_subject from People_for_edu,Result_testing,Topics Where (People_for_edu.id=Result_testing.id_people_for_edu)AND( Topics.Id=Result_testing.id_topic_of_testing)"; SqlCommand sqlCommand = new SqlCommand(sqlquery, sqlConnection); SqlDataReader reader = sqlCommand.ExecuteReader(); List<string[]> data = new List<string[]>(); Models.Temp[] data_test= new Models.Temp[100]; int k = 0; while (reader.Read()) { // int i = 0; data.Add(new string[7]); data[data.Count - 1][0] = reader[0].ToString(); data[data.Count - 1][1] = reader[1].ToString(); data[data.Count - 1][2] = reader[2].ToString(); data[data.Count - 1][3] = reader[3].ToString(); data[data.Count - 1][4] = reader[4].ToString(); data[data.Count - 1][5] = reader[5].ToString(); data[data.Count - 1][6] = reader[6].ToString(); /* data_test[i].familiya = reader[0].ToString(); data_test[i].name = reader[1].ToString(); data_test[i].otch = reader[2].ToString(); data_test[i].time = Convert.ToDateTime(reader[3].ToString()); data_test[i].prav= Convert.ToInt32(reader[4].ToString()); data_test[i].neprav = Convert.ToInt32(reader[5].ToString()); data_test[i].tema = reader[6].ToString();*/ // i++; } reader.Close(); sqlConnection.Close(); return data; // return data_test; } Client code:
private async void btn_click(object sender, System.EventArgs e) { Button button = (Button)sender; var data = await SendRequest(Url, "111"); int i = 1; } public async Task<string> SendRequest(string url, object body) { string data; using (var client = new HttpClient()) { var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); var result = await client.PostAsync(url, content); data = (await result.Content.ReadAsStringAsync()); // byte[] test = await result.Content.ReadAsByteArrayAsync(); // result.EnsureSuccessStatusCode(); // string json = @"{""familiy"": null,""name"": null,""otch"": null,""time"": null,""prav"": null,""neprav"": null,""tema"": null }"; //var data1 = JsonConvert.DeserializeObject<string>(data); //List<Temp> data1 = JsonConvert.DeserializeObject<List<Temp>>(data); int i = 1; // data_ = data1; } return data; } The data comes to the client in the form: "[[\" Chernyshov \ ", \" Alexey \ ", \" Viktorovich \ ", \" 11/02/2018 0:00:00 \ ", \" 3 \ ", \" 7 \ ", \" Works at height \ "], [\" Chernyshov \ ", \" Alexey \ ", \" Viktorovich \ ", \" 12/08/2018 0:00:00 \ ", \" 2 \ ", \ "8 \", \ "Mining works \"], [\ "Chernyshov \", \ "Alexey \", \ "Viktorovich \", \ "12/08/2018 0:00:00 \", \ "3 \ ", \" 7 \ ", \" Mining \ "]]"
I don’t understand what to do next, do I need to deserialize the data or how to get the opportunity to continue working with them?
List<string[]>format, so deserialization should go to what format? PS Very strange format ... - EvgeniyZ