Skip to content
This repository was archived by the owner on Feb 20, 2022. It is now read-only.

Commit 8785c08

Browse files
committed
1 parent 12cd090 commit 8785c08

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

unity-project/Assets/3rd party/JSONObject/JSONObject.cs

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3333
THE SOFTWARE.
3434
*/
3535

36-
public class JSONObject {
36+
public class JSONObject : IEnumerable {
3737
#if POOLING
3838
const int MAX_POOL_SIZE = 10000;
3939
public static Queue<JSONObject> releaseQueue = new Queue<JSONObject>();
@@ -416,7 +416,7 @@ void Parse(string str, int maxDepth = -2, bool storeExcessLevels = false, bool s
416416
if(type == Type.OBJECT)
417417
keys.Add(propName);
418418
if(maxDepth != -1) //maxDepth of -1 is the end of the line
419-
list.Add(Create(inner, (maxDepth < -1) ? -2 : maxDepth - 1));
419+
list.Add(Create(inner, (maxDepth < -1) ? -2 : maxDepth - 1, storeExcessLevels));
420420
else if(storeExcessLevels)
421421
list.Add(CreateBakedObject(inner));
422422

@@ -1120,4 +1120,64 @@ public static void ClearPool() {
11201120
}
11211121
}
11221122
#endif
1123+
1124+
IEnumerator IEnumerable.GetEnumerator()
1125+
{
1126+
return (IEnumerator)GetEnumerator();
1127+
}
1128+
1129+
public JSONObjectEnumer GetEnumerator()
1130+
{
1131+
return new JSONObjectEnumer(this);
1132+
}
1133+
}
1134+
1135+
public class JSONObjectEnumer : IEnumerator
1136+
{
1137+
public JSONObject _jobj;
1138+
1139+
// Enumerators are positioned before the first element
1140+
// until the first MoveNext() call.
1141+
int position = -1;
1142+
1143+
public JSONObjectEnumer(JSONObject jsonObject)
1144+
{
1145+
Debug.Assert(jsonObject.isContainer); //must be an array or object to itterate
1146+
_jobj = jsonObject;
1147+
}
1148+
1149+
public bool MoveNext()
1150+
{
1151+
position++;
1152+
return (position < _jobj.Count);
1153+
}
1154+
1155+
public void Reset()
1156+
{
1157+
position = -1;
1158+
}
1159+
1160+
object IEnumerator.Current
1161+
{
1162+
get
1163+
{
1164+
return Current;
1165+
}
1166+
}
1167+
1168+
public JSONObject Current
1169+
{
1170+
get
1171+
{
1172+
if (_jobj.IsArray)
1173+
{
1174+
return _jobj[position];
1175+
}
1176+
else
1177+
{
1178+
string key = _jobj.keys[position];
1179+
return _jobj[key];
1180+
}
1181+
}
1182+
}
11231183
}

unity-project/Assets/3rd party/JSONObject/readme.md.meta

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)