Skip to content

Commit 20c0679

Browse files
committed
Replace global typeof with JSON.typeof(...)
1 parent 3f531cd commit 20c0679

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

examples/JSONArray/JSONArray.ino

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ void demoParse() {
2929

3030
JSONVar myArray = JSON.parse(input);
3131

32-
// typeof(jsonVar) can be used to get the type of the var
33-
if (typeof(myArray) == "undefined") {
32+
// JSON.typeof(jsonVar) can be used to get the type of the var
33+
if (JSON.typeof(myArray) == "undefined") {
3434
Serial.println("Parsing input failed!");
3535
return;
3636
}
3737

38-
Serial.print("typeof(myArray) = ");
39-
Serial.println(typeof(myArray)); // prints: array
38+
Serial.print("JSON.typeof(myArray) = ");
39+
Serial.println(JSON.typeof(myArray)); // prints: array
4040

4141
// myArray.length() can be used to get the length of the array
4242
Serial.print("myArray.length() = ");
4343
Serial.println(myArray.length());
4444
Serial.println();
4545

46-
Serial.print("typeof(myArray[0]) = ");
47-
Serial.println(typeof(myArray[0]));
46+
Serial.print("JSON.typeof(myArray[0]) = ");
47+
Serial.println(JSON.typeof(myArray[0]));
4848

4949
Serial.print("myArray[0] = ");
5050
Serial.println(myArray[0]);
@@ -87,10 +87,10 @@ void demoCreation() {
8787
for (int i = 0; i < myArray.length(); i++) {
8888
JSONVar value = myArray[i];
8989

90-
Serial.print("typeof(myArray[");
90+
Serial.print("JSON.typeof(myArray[");
9191
Serial.print(i);
9292
Serial.print("]) = ");
93-
Serial.println(typeof(value));
93+
Serial.println(JSON.typeof(value));
9494

9595
Serial.print("myArray[");
9696
Serial.print(i);

examples/JSONKitchenSink/JSONKitchenSink.ino

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ void booleanDemo() {
3636

3737
JSONVar myBoolean = true;
3838

39-
Serial.print("typeof(myBoolean) = ");
40-
Serial.println(typeof(myBoolean)); // prints: boolean
39+
Serial.print("JSON.typeof(myBoolean) = ");
40+
Serial.println(JSON.typeof(myBoolean)); // prints: boolean
4141

4242
Serial.print("myBoolean = ");
4343
Serial.println(myBoolean); // prints: true
@@ -56,8 +56,8 @@ void intDemo() {
5656

5757
JSONVar myInt = 42;
5858

59-
Serial.print("typeof(myInt) = ");
60-
Serial.println(typeof(myInt)); // prints: number
59+
Serial.print("JSON.typeof(myInt) = ");
60+
Serial.println(JSON.typeof(myInt)); // prints: number
6161

6262
Serial.print("myInt = ");
6363
Serial.println(myInt); // prints: 42
@@ -76,8 +76,8 @@ void doubleDemo() {
7676

7777
JSONVar myDouble = 42.5;
7878

79-
Serial.print("typeof(myDouble) = ");
80-
Serial.println(typeof(myDouble)); // prints: number
79+
Serial.print("JSON.typeof(myDouble) = ");
80+
Serial.println(JSON.typeof(myDouble)); // prints: number
8181

8282
Serial.print("myDouble = ");
8383
Serial.println(myDouble); // prints: 42.5
@@ -96,8 +96,8 @@ void stringDemo() {
9696

9797
JSONVar myString = "Hello World!";
9898

99-
Serial.print("typeof(myString) = ");
100-
Serial.println(typeof(myString)); // prints: string
99+
Serial.print("JSON.typeof(myString) = ");
100+
Serial.println(JSON.typeof(myString)); // prints: string
101101

102102
Serial.print("myString = ");
103103
Serial.println(myString); // prints: Hello World!
@@ -118,8 +118,8 @@ void arrayDemo() {
118118

119119
myArray[0] = 42;
120120

121-
Serial.print("typeof(myArray) = ");
122-
Serial.println(typeof(myArray)); // prints: array
121+
Serial.print("JSON.typeof(myArray) = ");
122+
Serial.println(JSON.typeof(myArray)); // prints: array
123123

124124
Serial.print("myArray = ");
125125
Serial.println(myArray); // prints: [42]
@@ -146,8 +146,8 @@ void objectDemo() {
146146

147147
myObject["foo"] = "bar";
148148

149-
Serial.print("typeof(myObject) = ");
150-
Serial.println(typeof(myObject)); // prints: object
149+
Serial.print("JSON.typeof(myObject) = ");
150+
Serial.println(JSON.typeof(myObject)); // prints: object
151151

152152
Serial.print("myObject.keys() = ");
153153
Serial.println(myObject.keys()); // prints: ["foo"]

examples/JSONObject/JSONObject.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ void demoParse() {
2929

3030
JSONVar myObject = JSON.parse(input);
3131

32-
// typeof(jsonVar) can be used to get the type of the var
33-
if (typeof(myObject) == "undefined") {
32+
// JSON.typeof(jsonVar) can be used to get the type of the var
33+
if (JSON.typeof(myObject) == "undefined") {
3434
Serial.println("Parsing input failed!");
3535
return;
3636
}
3737

38-
Serial.print("typeof(myObject) = ");
39-
Serial.println(typeof(myObject)); // prints: object
38+
Serial.print("JSON.typeof(myObject) = ");
39+
Serial.println(JSON.typeof(myObject)); // prints: object
4040

4141
// myObject.hasOwnProperty(key) checks if the object contains an entry for key
4242
if (myObject.hasOwnProperty("result")) {
@@ -97,10 +97,10 @@ void demoCreation() {
9797
for (int i = 0; i < keys.length(); i++) {
9898
JSONVar value = myObject[keys[i]];
9999

100-
Serial.print("typeof(myObject[");
100+
Serial.print("JSON.typeof(myObject[");
101101
Serial.print(keys[i]);
102102
Serial.print("]) = ");
103-
Serial.println(typeof(value));
103+
Serial.println(JSON.typeof(value));
104104

105105
Serial.print("myObject[");
106106
Serial.print(keys[i]);

src/JSON.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ JSONClass::~JSONClass()
7272
{
7373
}
7474

75-
String typeof(const JSONVar& value)
76-
{
77-
return JSONVar::typeof(value);
78-
}
79-
8075
JSONVar JSONClass::parse(const char* s)
8176
{
8277
return JSONVar::parse(s);
@@ -92,4 +87,9 @@ String JSONClass::stringify(const JSONVar& value)
9287
return JSONVar::stringify(value);
9388
}
9489

90+
String JSONClass::typeof(const JSONVar& value)
91+
{
92+
return JSONVar::typeof(value);
93+
}
94+
9595
JSONClass JSON;

src/JSON.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
#include "JSONVar.h"
2626

27-
String typeof(const JSONVar& value);
28-
2927
class JSONClass {
3028
public:
3129
JSONClass();
@@ -35,6 +33,8 @@ class JSONClass {
3533
JSONVar parse(const String& s);
3634

3735
String stringify(const JSONVar& value);
36+
37+
String typeof(const JSONVar& value);
3838
};
3939

4040
extern JSONClass JSON;

0 commit comments

Comments
 (0)