6
6
using UnityEngine . Networking ;
7
7
#endif
8
8
9
+ #if PERFTEST && UNITY_5_6_OR_NEWER
10
+ using UnityEngine . Profiling ;
11
+ #endif
12
+
9
13
/*
10
14
Copyright (c) 2010-2019 Matt Schoen
11
15
@@ -28,8 +32,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
32
THE SOFTWARE.
29
33
*/
30
34
31
- public class JSONChecker : EditorWindow {
32
- string JSON = @"{
35
+ namespace Defective . JSON {
36
+ public class JSONChecker : EditorWindow {
37
+ string JSON = @"{
33
38
""TestObject"": {
34
39
""SomeText"": ""Blah"",
35
40
""SomeObject"": {
@@ -43,70 +48,77 @@ public class JSONChecker : EditorWindow {
43
48
""SomeEmptyArray"": [ ],
44
49
""EmbeddedObject"": ""{\""field\"":\""Value with \\\""escaped quotes\\\""\""}""
45
50
}
46
- }" ; //dat string literal...
47
- string URL = "" ;
48
- JSONObject j ;
49
- [ MenuItem ( "Window/JSONChecker" ) ]
50
- static void Init ( ) {
51
- GetWindow ( typeof ( JSONChecker ) ) ;
52
- }
53
- void OnGUI ( ) {
54
- JSON = EditorGUILayout . TextArea ( JSON ) ;
55
- GUI . enabled = ! string . IsNullOrEmpty ( JSON ) ;
56
- if ( GUILayout . Button ( "Check JSON" ) ) {
51
+ }" ; //dat string literal...
52
+
53
+ string URL = "" ;
54
+ JSONObject j ;
55
+
56
+ [ MenuItem ( "Window/JSONChecker" ) ]
57
+ static void Init ( ) {
58
+ GetWindow ( typeof ( JSONChecker ) ) ;
59
+ }
60
+
61
+ void OnGUI ( ) {
62
+ JSON = EditorGUILayout . TextArea ( JSON ) ;
63
+ GUI . enabled = ! string . IsNullOrEmpty ( JSON ) ;
64
+ if ( GUILayout . Button ( "Check JSON" ) ) {
57
65
#if PERFTEST
58
- Profiler . BeginSample ( "JSONParse" ) ;
59
- j = JSONObject . Create ( JSON ) ;
60
- Profiler . EndSample ( ) ;
61
- Profiler . BeginSample ( "JSONStringify" ) ;
62
- j . ToString ( true ) ;
63
- Profiler . EndSample ( ) ;
66
+ Profiler . BeginSample ( "JSONParse" ) ;
67
+ j = JSONObject . Create ( JSON ) ;
68
+ Profiler . EndSample ( ) ;
69
+ Profiler . BeginSample ( "JSONStringify" ) ;
70
+ j . ToString ( true ) ;
71
+ Profiler . EndSample ( ) ;
64
72
#else
65
- j = JSONObject . Create ( JSON ) ;
73
+ j = JSONObject . Create ( JSON ) ;
66
74
#endif
67
- Debug . Log ( j . ToString ( true ) ) ;
68
- }
69
- EditorGUILayout . Separator ( ) ;
70
- URL = EditorGUILayout . TextField ( "URL" , URL ) ;
71
- if ( GUILayout . Button ( "Get JSON" ) ) {
72
- Debug . Log ( URL ) ;
75
+ Debug . Log ( j . ToString ( true ) ) ;
76
+ }
77
+
78
+ EditorGUILayout . Separator ( ) ;
79
+ URL = EditorGUILayout . TextField ( "URL" , URL ) ;
80
+ if ( GUILayout . Button ( "Get JSON" ) ) {
81
+ Debug . Log ( URL ) ;
73
82
#if UNITY_2017_1_OR_NEWER
74
- var test = new UnityWebRequest ( URL ) ;
83
+ var test = new UnityWebRequest ( URL ) ;
75
84
76
85
#if UNITY_2017_2_OR_NEWER
77
- test . SendWebRequest ( ) ;
86
+ test . SendWebRequest ( ) ;
78
87
#else
79
88
test . Send ( ) ;
80
89
#endif
81
90
#if UNITY_2020_1_OR_NEWER
82
91
while ( ! test . isDone && test . result != UnityWebRequest . Result . ConnectionError ) { }
83
92
#else
84
- while ( ! test . isDone && ! test . isNetworkError ) { }
93
+ while ( ! test . isDone && ! test . isNetworkError ) {
94
+ }
85
95
#endif
86
96
#else
87
97
var test = new WWW ( URL ) ;
88
98
while ( ! test . isDone ) ;
89
99
#endif
90
- if ( ! string . IsNullOrEmpty ( test . error ) ) {
91
- Debug . Log ( test . error ) ;
92
- } else {
100
+ if ( ! string . IsNullOrEmpty ( test . error ) ) {
101
+ Debug . Log ( test . error ) ;
102
+ } else {
93
103
#if UNITY_2017_1_OR_NEWER
94
- var text = test . downloadHandler . text ;
104
+ var text = test . downloadHandler . text ;
95
105
#else
96
106
var text = test . text ;
97
107
#endif
98
- Debug . Log ( text ) ;
99
- j = new JSONObject ( text ) ;
100
- Debug . Log ( j . ToString ( true ) ) ;
108
+ Debug . Log ( text ) ;
109
+ j = new JSONObject ( text ) ;
110
+ Debug . Log ( j . ToString ( true ) ) ;
111
+ }
101
112
}
102
- }
103
- if ( j ) {
104
- //Debug.Log(System.GC.GetTotalMemory(false) + "");
105
- if ( j . type == JSONObject . Type . NULL )
106
- GUILayout . Label ( "JSON fail:\n " + j . ToString ( true ) ) ;
107
- else
108
- GUILayout . Label ( "JSON success:\n " + j . ToString ( true ) ) ;
109
113
114
+ if ( j ) {
115
+ //Debug.Log(System.GC.GetTotalMemory(false) + "");
116
+ if ( j . type == JSONObject . Type . NULL )
117
+ GUILayout . Label ( "JSON fail:\n " + j . ToString ( true ) ) ;
118
+ else
119
+ GUILayout . Label ( "JSON success:\n " + j . ToString ( true ) ) ;
120
+
121
+ }
110
122
}
111
123
}
112
- }
124
+ }
0 commit comments