Skip to content

Commit 2811be0

Browse files
authored
Merge pull request #18 from aahill/entity-search-update
Bing Entity Search API quickstart update
2 parents fbd90e0 + f29b47d commit 2811be0

File tree

1 file changed

+5
-66
lines changed

1 file changed

+5
-66
lines changed
Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
using Newtonsoft.Json;
12
using System;
23
using System.Net.Http;
3-
using System.Text;
44

55
namespace EntitySearchSample
66
{
@@ -12,7 +12,7 @@ class Program
1212
static string market = "en-US";
1313

1414
// NOTE: Replace this example key with a valid subscription key.
15-
static string key = "ENTER KEY HERE";
15+
static string key = "ENTER YOUR KEY HERE";
1616

1717
static string query = "italian restaurant near me";
1818

@@ -26,7 +26,9 @@ async static void Search()
2626
HttpResponseMessage response = await client.GetAsync(uri);
2727

2828
string contentString = await response.Content.ReadAsStringAsync();
29-
Console.WriteLine(JsonPrettyPrint(contentString));
29+
dynamic parsedJson = JsonConvert.DeserializeObject(contentString);
30+
31+
Console.WriteLine(parsedJson);
3032
}
3133

3234
static void Main(string[] args)
@@ -35,68 +37,5 @@ static void Main(string[] args)
3537
Console.ReadLine();
3638
}
3739

38-
39-
static string JsonPrettyPrint(string json)
40-
{
41-
if (string.IsNullOrEmpty(json))
42-
return string.Empty;
43-
44-
json = json.Replace(Environment.NewLine, "").Replace("\t", "");
45-
46-
StringBuilder sb = new StringBuilder();
47-
bool quote = false;
48-
bool ignore = false;
49-
int offset = 0;
50-
int indentLength = 3;
51-
52-
foreach (char ch in json)
53-
{
54-
switch (ch)
55-
{
56-
case '"':
57-
if (!ignore) quote = !quote;
58-
break;
59-
case '\'':
60-
if (quote) ignore = !ignore;
61-
break;
62-
}
63-
64-
if (quote)
65-
sb.Append(ch);
66-
else
67-
{
68-
switch (ch)
69-
{
70-
case '{':
71-
case '[':
72-
sb.Append(ch);
73-
sb.Append(Environment.NewLine);
74-
sb.Append(new string(' ', ++offset * indentLength));
75-
break;
76-
case '}':
77-
case ']':
78-
sb.Append(Environment.NewLine);
79-
sb.Append(new string(' ', --offset * indentLength));
80-
sb.Append(ch);
81-
break;
82-
case ',':
83-
sb.Append(ch);
84-
sb.Append(Environment.NewLine);
85-
sb.Append(new string(' ', offset * indentLength));
86-
break;
87-
case ':':
88-
sb.Append(ch);
89-
sb.Append(' ');
90-
break;
91-
default:
92-
if (ch != ' ') sb.Append(ch);
93-
break;
94-
}
95-
}
96-
}
97-
98-
return sb.ToString().Trim();
99-
}
100-
10140
}
10241
}

0 commit comments

Comments
 (0)