Skip to content

Commit 479a7a2

Browse files
Make add boxes json a bit less obtuse
1 parent 5486033 commit 479a7a2

2 files changed

Lines changed: 44 additions & 32 deletions

File tree

DotNET/Endpoint Examples/JSON Payload/pdf-with-page-boxes-set.cs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,33 @@
3333

3434
SetBoxesRequest.Headers.TryAddWithoutValidation("Content-Type", "application/json");
3535

36-
var boxes_option_array = new JArray();
37-
var boxes_option1 = new JObject
36+
var boxOptions = new JObject
3837
{
39-
["box"] = "media",
40-
["pages"] = new JArray();
41-
};
42-
var pages_option1 = new JObject
38+
["boxes"] = new JArray
4339
{
44-
["range"] = "1",
45-
["left"] = "100",
46-
["right"] = "100",
47-
["top"] = "100",
48-
["bottom"] = "100",
40+
new JObject
41+
{
42+
["box"] = "media",
43+
["pages"] = new JArray
44+
{
45+
new JObject
46+
{
47+
["range"] = "1",
48+
["left"] = 100,
49+
["top"] = 100,
50+
["bottom"] = 100,
51+
["right"] = 100
52+
}
53+
}
54+
}
55+
}
4956
};
50-
((JArray)boxes_option1["pages"]).Add(pages_option1);
51-
boxes_option_array.Add(boxes_option1);
5257

5358
JObject parameterJson = new JObject
54-
{
55-
["id"] = uploadedID,
56-
["boxes"] = JsonConvert.SerializeObject(boxes_option_array),
57-
};
59+
{
60+
["id"] = uploadedID,
61+
["boxes"] = boxOptions.ToString(Formatting.None),
62+
};
5863

5964
SetBoxesRequest.Content = new StringContent(parameterJson.ToString(), Encoding.UTF8, "application/json"); ;
6065
var SetBoxesResponse = await httpClient.SendAsync(SetBoxesRequest);

DotNET/Endpoint Examples/Multipart Payload/pdf-with-page-boxes-set.cs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,30 @@
1515
multipartContent.Add(byteAryContent, "file", "file_name.pdf");
1616
byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf");
1717

18-
var boxes_option_array = new JArray();
19-
var boxes_option1 = new JObject
18+
var boxOptions = new JObject
2019
{
21-
["box"] = "media",
22-
["pages"] = new JArray();
20+
["boxes"] = new JArray
21+
{
22+
new JObject
23+
{
24+
["box"] = "media",
25+
["pages"] = new JArray
26+
{
27+
new JObject
28+
{
29+
["range"] = "1",
30+
["left"] = 100,
31+
["top"] = 100,
32+
["bottom"] = 100,
33+
["right"] = 100
34+
}
35+
}
36+
}
37+
}
2338
};
24-
var pages_option1 = new JObject
25-
{
26-
["range"] = "1",
27-
["left"] = "100",
28-
["right"] = "100",
29-
["top"] = "100",
30-
["bottom"] = "100",
31-
};
32-
((JArray)boxes_option1["pages"]).Add(pages_option1);
33-
boxes_option_array.Add(boxes_option1);
34-
var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(boxes_option_array)));
39+
40+
41+
var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes(boxOptions.ToString(Formatting.None)));
3542
multipartContent.Add(byteArrayOption, "boxes");
3643

3744

0 commit comments

Comments
 (0)