У меня возникли проблемы с группировкой возврата JSON.
Мне нужно дать группе массивов имя.
Я нашел много информации в Интернете, но это меня смущает. У меня нет большого опыта в этом, поэтому любая помощь полезна.
Спасибо за ввод!
Вот мой код:
public ArrayList Get()
{
ArrayList objs = new ArrayList();
try
{
FIREBIRD.ConnectionString = ConfigurationManager.ConnectionStrings["Firebird"].ConnectionString;
FIREBIRD.Open();
FbDataReader reader = null;
FbCommand command = new FbCommand("SOME QUERY", FIREBIRD);
reader = command.ExecuteReader();
if (reader.HasRows == true)
{
while (reader.Read())
{
objs.Add(new
{
id = reader["CODE"],
name = reader["TITE"],
address = reader["ADRES"],
postal_code = reader["POSTAL"],
city = reader["CITY"]
});
}
return objs;
}
else
{
objs.Add(new { ERROR = "NO DATA AVAILABLE" });
return objs;
}
}
catch (Exception)
{
throw;
}
finally
{
FIREBIRD.Close();
}
}
}
Текущий доход:
[{
"id": "code",
"name": "name",
"address": "adres",
"postal_code": "1234",
"city": "city"
}]
Что должно возвращаться:
{"sites":
[{
"id": "code",
"name": "name",
"address": "adres",
"postal_code": "1234",
"city": "city"
}]
}