Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check if JSONNode contains a key quickly? #4

Open
ROBYER1 opened this issue Apr 7, 2021 · 0 comments
Open

How to check if JSONNode contains a key quickly? #4

ROBYER1 opened this issue Apr 7, 2021 · 0 comments

Comments

@ROBYER1
Copy link

ROBYER1 commented Apr 7, 2021

Hey, been using this repo for a while in projects and it works a treat, I was looking at ways to check quickly if a JSON Node contains a key, and wasn't able to find a way to do that with your version - I tried the below script but there is no definition for node.Keys in your repo.

This works with the Bunny83 SimpleJSON latest version, but we ran into another issue with their version of SimpleJSON where checking if the JSON Node was null in an if statement always returned false even if the JSON was empty! Bunny83/SimpleJSON#45 - I have reported that issue to them there referencing your repo

So your version is great for checking if a JSON Node is null, but there is no way I could see to check quickly if a JSONNode contains a key with yours other than looping through the JSON Node by a section I defined and checking if values contain a string which feels slow - any tips?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace SimpleJSON
{
public class JSONNodeExtension : MonoBehaviour {

	public static bool ContainsKey(SimpleJSON.JSONNode node, string checkKey)
	{
		foreach (string key in node.Keys)
		{
			if (key == checkKey)
				return true;
		}
		return false;
	}

}

}

Thanks for the great and robust version of SimpleJSON

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant