Пример #1
0
        public static byte[] searchResponse(Dictionary <string, string> searchTerms = null)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                using (Utf8JsonWriter writer = new Utf8JsonWriter(stream, JW_OPTS))
                {
                    writer.WriteStartObject();
                    writer.WriteStartArray("items");
                    List <Item> items = DataBase.getItems(searchTerms);
                    if (items == null)
                    {
                        return(null);
                    }
                    foreach (Item i in items)
                    {
                        writer.WriteStartObject();
                        writer.WriteNumber("id", i.id);
                        writer.WriteString("name", i.name);
                        writer.WriteNumber("price", i.price);
                        writer.WriteNumber("current", i.current);
                        writer.WriteString("category", i.category);
                        writer.WriteString("image", i.image);
                        writer.WriteEndObject();
                    }
                    writer.WriteEndArray();
                    writer.WriteEndObject();
                }

                return(stream.ToArray());
            }
        }