本文整理汇总了C#中JSONObject.HasField方法的典型用法代码示例。如果您正苦于以下问题:C# JSONObject.HasField方法的具体用法?C# JSONObject.HasField怎么用?C# JSONObject.HasField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONObject
的用法示例。
在下文中一共展示了JSONObject.HasField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
public static void Deserialize(this Template template)
{
template.Clear();
var tplJs = new JSONObject(template.JSON);
// Discard templates without the Operators and Connections fields
if (tplJs.HasField("Operators") && tplJs.HasField("Connections")) {
var opsJs = tplJs.GetField("Operators");
var connsJs = tplJs.GetField("Connections");
foreach (var opJs in opsJs.list) {
var type = System.Type.GetType(opJs["Type"].str);
var op = (Operator) System.Activator.CreateInstance(type);
op.Deserialize(opJs);
template.AddOperator(op, false);
}
foreach (var connJs in connsJs.list) {
// Discard connections with invalid Operator GUIDs
if (!template.Operators.ContainsKey(connJs["From"].str) || !template.Operators.ContainsKey(connJs["To"].str)) {
Debug.LogWarning("Discarding connection in template due to an invalid Operator GUID");
continue;
}
Operator fromOp = template.Operators[connJs["From"].str];
IOOutlet output = fromOp.GetOutput(connJs["Output"].str);
Operator toOp = template.Operators[connJs["To"].str];
IOOutlet input = toOp.GetInput(connJs["Input"].str);
template.Connect(fromOp, output, toOp, input, false);
}
}
}
示例2: UnSerialize
public static JSONAble UnSerialize(JSONObject jsonObject)
{
JSONAble r = null;
if (jsonObject.HasField("_class") && jsonObject.HasField("_data"))
{
string c = jsonObject.GetField("_class").str;
Type t = Type.GetType(c);
if (t.IsSubclassOf(typeof(JSONAble)))
{
if (t.IsSubclassOf(typeof(ScriptableObject)))
{
r = ScriptableObject.CreateInstance(t) as JSONAble;
r.fromJSONObject(jsonObject.GetField("_data"));
}
}
}
else if (jsonObject.IsArray)
{
r = ScriptableObject.CreateInstance<IsoUnityCollectionType>();
r.fromJSONObject(jsonObject);
}
else if (jsonObject.IsString || jsonObject.IsNumber || jsonObject.IsBool)
{
r = ScriptableObject.CreateInstance<IsoUnityBasicType>();
r.fromJSONObject(jsonObject);
}
return r;
}
示例3: ParseUnitObject
public static bool ParseUnitObject( JSONObject _UnitNode ,
ref string _UnitName ,
ref string _PrefabName ,
ref Vector3 _InitPosition ,
ref Quaternion _InitQuaternion )
{
if( true == _UnitNode.HasField( "name" ) &&
true == _UnitNode.HasField( "prefabName" )
)
{
_UnitName = _UnitNode.GetField( "name" ).str ;
Debug.Log( "JSonParseUtility01:ParseUnitObject() _UnitName=" + _UnitName) ;
_PrefabName = _UnitNode.GetField( "prefabName" ).str ;
if( true == _UnitNode.HasField( "position3D" ) )
{
JSONObject positione3DNode = _UnitNode.GetField( "position3D" ) ;
ParsePosition( positione3DNode ,
ref _InitPosition ) ;
}
if( true == _UnitNode.HasField( "orientationEuler" ) )
{
JSONObject orientationNode = _UnitNode.GetField( "orientationEuler" ) ;
ParseQuaternion( orientationNode ,
ref _InitQuaternion ) ;
}
return true ;
}
return false ;
}
示例4: CreateFromJson
public static GameModeDescription CreateFromJson(JSONObject jsonObject)
{
if (jsonObject == null)
{
Debug.LogWarning("There is no gameMode");
return new GameModeDescription()
{
Mode = "TargetScore",
TargetScore = 3000,
Turns = 40
};
/*return new GameModeDescription()
{
Mode = "TargetChuzzle",
Turns = 30,
Amount = 20
};*/
/*return new GameModeDescription()
{
Mode = "TargetPlace",
Turns = 30
};*/
}
var desc = new GameModeDescription
{
Mode = jsonObject.GetField("Mode").str,
Turns = (int) jsonObject.GetField("Turns").n,
TargetScore = jsonObject.HasField("TargetScore") ? (int) jsonObject.GetField("TargetScore").n : 0,
Amount = jsonObject.HasField("Amount") ? (int) jsonObject.GetField("Amount").n : 0
};
return desc;
}
示例5: FromJson
public static SerializedLevel FromJson(JSONObject jsonObject)
{
Debug.Log("Print: \n" + jsonObject);
var serializedLevel = new SerializedLevel();
serializedLevel.Name = jsonObject.GetField("name").str;
serializedLevel.Width = (int) jsonObject.GetField("width").n;
serializedLevel.Height = (int) jsonObject.GetField("height").n;
serializedLevel.NumberOfColors = jsonObject.HasField("numberOfColors")
? (int) jsonObject.GetField("numberOfColors").n
: 6;
serializedLevel.Seed = jsonObject.HasField("seed") ? (int) jsonObject.GetField("seed").n : 1;
serializedLevel.GameMode = GameModeDescription.CreateFromJson(jsonObject.GetField("gameMode"));
var array = jsonObject.GetField("map").list;
foreach (var tile in array)
{
var x = array.IndexOf(tile)%serializedLevel.Width;
var y = serializedLevel.Height - (array.IndexOf(tile)/serializedLevel.Width) - 1;
var tileType = (int) tile.n;
switch (tileType)
{
case (0): //empty
break;
case (2): // place
serializedLevel.SpecialCells.Add(new Cell(x, y) {HasPlace = true});
break;
case (3): //counter
serializedLevel.SpecialCells.Add(new Cell(x, y) {HasCounter = true});
break;
default: // block
serializedLevel.SpecialCells.Add(new Cell(x, y, CellTypes.Block));
break;
}
}
serializedLevel.Stages = CreateStagesFromJsonObject(jsonObject.GetField("stages"));
serializedLevel.Star1Score = jsonObject.HasField("Star1Score")
? (int) jsonObject.GetField("Star1Score").n
: 1000;
serializedLevel.Star2Score = jsonObject.HasField("Star2Score")
? (int) jsonObject.GetField("Star2Score").n
: 2000;
serializedLevel.Star3Score = jsonObject.HasField("Star3Score")
? (int) jsonObject.GetField("Star3Score").n
: 3000;
return serializedLevel;
}
示例6: GetErrorMessage
public string GetErrorMessage(JSONObject json)
{
if (json.HasField(((int) ParameterCode.Error).ToString()))
{
return json.GetField(((int) ParameterCode.Error).ToString()).str;
}
return null;
}
示例7: ParsePosition
// 分析位置 包含座標及位置物件
public static bool ParsePosition( JSONObject _PositionNode ,
ref Vector3 _Pos )
{
if( true == _PositionNode.HasField( "x" ) &&
true == _PositionNode.HasField( "y" ) &&
true == _PositionNode.HasField( "z" ) )
{
string strx = _PositionNode.GetField("x").str ;
string stry = _PositionNode.GetField("y").str ;
string strz = _PositionNode.GetField("z").str ;
float x , y , z ;
float.TryParse( strx , out x ) ;
float.TryParse( stry , out y ) ;
float.TryParse( strz , out z ) ;
_Pos = new Vector3( x , y , z ) ;
return true ;
}
return false ;
}
示例8: getConfigValue
public static string getConfigValue(string key)
{
JSONObject config = new JSONObject(GameConfigData);
if(config.HasField("key")){
return config.GetField(key).Print(false);
}
return null;
}
示例9: ParseQuaternion
// 分析旋轉
public static bool ParseQuaternion( JSONObject _OrientationNode ,
ref Quaternion _Orientation )
{
if( true == _OrientationNode.HasField( "x" ) &&
true == _OrientationNode.HasField( "y" ) &&
true == _OrientationNode.HasField( "z" ) )
{
string strx = _OrientationNode.GetField("x").str ;
string stry = _OrientationNode.GetField("y").str ;
string strz = _OrientationNode.GetField("z").str ;
float x , y , z ;
float.TryParse( strx , out x ) ;
float.TryParse( stry , out y ) ;
float.TryParse( strz , out z ) ;
_Orientation = Quaternion.Euler( -x , -y , -z ) ;
// Debug.Log( "XMLParseUtilityPartial02:ParseQuaternion() x=" + x + "," + y + ",z" + z ) ;
return true ;
}
return false ;
}
示例10: CheckSlotGameConifg
public static void CheckSlotGameConifg()
{
JSONObject slotConfigJSON = new JSONObject(GetData("requestConfig"));
JSONObject localConfigJSON = new JSONObject(System.IO.File.ReadAllText (Application.streamingAssetsPath + "/defaultGameConfig.json"));
if(slotConfigJSON.HasField("androidSdkConfig") && localConfigJSON.HasField("androidSdkConfig")){
string slotConfig = slotConfigJSON.GetField("androidSdkConfig").Print(false);
string localConfig = localConfigJSON.GetField("androidSdkConfig").Print(false);
if(!localConfig.Equals(slotConfig)){
UnityEngine.Debug.Log("The local \"defaultGameConfig.json\" file is out-of-sync with the SLOT configuration. Please make sure to update your file with the latest changes from SLOT before building!");
}
}
}
示例11: MarketItem
/**
* Constructor.
* Generates an instance of <code>MarketItem</code> from a <code>JSONObject</code>.
*
* @param jsonObject a <code>JSONObject</code> representation of the wanted
* <code>MarketItem</code>.
* @throws JSONException
*/
public MarketItem(JSONObject jsonObject)
{
//MarketItem miDeserialized = Newtonsoft.Json.JsonConvert.DeserializeObject<MarketItem>(jsonObject.ToString());
if (jsonObject.HasField(StoreJSONConsts.MARKETITEM_MANAGED))
{
int isManaged = (int)jsonObject[StoreJSONConsts.MARKETITEM_MANAGED].n;
SoomlaUtils.LogDebug(TAG, isManaged.ToString());
if (isManaged == 0)
{
this.mManaged = Managed.MANAGED;
}
else
{
this.mManaged = Managed.UNMANAGED;
}
}
else
{
this.mManaged = Managed.UNMANAGED;
}
if (jsonObject.HasField(StoreJSONConsts.MARKETITEM_PRODUCT_ID))
{
this.mProductId = jsonObject[StoreJSONConsts.MARKETITEM_PRODUCT_ID].str;
}
else
{
SoomlaUtils.LogError(TAG, "Market Item No Product ID");
}
this.mPrice = (double)jsonObject[StoreJSONConsts.MARKETITEM_PRICE].n;
this.mMarketPriceAndCurrency = jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICE].str;
this.mMarketTitle = jsonObject[StoreJSONConsts.MARKETITEM_MARKETTITLE].str;
this.mMarketDescription = jsonObject[StoreJSONConsts.MARKETITEM_MARKETDESC].str;
this.mMarketCurrencyCode = jsonObject[StoreJSONConsts.MARKETITEM_MARKETCURRENCYCODE].str;
this.mMarketPriceMicros = (long)jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICEMICROS].n;
}
示例12: MarketItem
/// <summary>
/// Constructor.
/// Generates an instance of <c>MarketItem</c> from a <c>JSONObject<c>.
/// </summary>
/// <param name="jsonObject">A <c>JSONObject</c> representation of the wanted
/// <c>MarketItem</c>.</param>
public MarketItem(JSONObject jsonObject)
{
string keyToLook = "";
#if UNITY_IOS && !UNITY_EDITOR
keyToLook = StoreJSONConsts.MARKETITEM_IOS_ID;
#elif UNITY_ANDROID && !UNITY_EDITOR
keyToLook = StoreJSONConsts.MARKETITEM_ANDROID_ID;
#endif
if (!string.IsNullOrEmpty(keyToLook) && jsonObject.HasField(keyToLook)) {
ProductId = jsonObject[keyToLook].str;
} else {
ProductId = jsonObject[StoreJSONConsts.MARKETITEM_PRODUCT_ID].str;
}
Price = jsonObject[StoreJSONConsts.MARKETITEM_PRICE].n;
int cOrdinal = System.Convert.ToInt32(((JSONObject)jsonObject[StoreJSONConsts.MARKETITEM_CONSUMABLE]).n);
if (cOrdinal == 0) {
this.consumable = Consumable.NONCONSUMABLE;
} else if (cOrdinal == 1){
this.consumable = Consumable.CONSUMABLE;
} else {
this.consumable = Consumable.SUBSCRIPTION;
}
if (jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICE]) {
this.MarketPriceAndCurrency = jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICE].str;
} else {
this.MarketPriceAndCurrency = "";
}
if (jsonObject[StoreJSONConsts.MARKETITEM_MARKETTITLE]) {
this.MarketTitle = jsonObject[StoreJSONConsts.MARKETITEM_MARKETTITLE].str;
} else {
this.MarketTitle = "";
}
if (jsonObject[StoreJSONConsts.MARKETITEM_MARKETDESC]) {
this.MarketDescription = jsonObject[StoreJSONConsts.MARKETITEM_MARKETDESC].str;
} else {
this.MarketDescription = "";
}
if (jsonObject[StoreJSONConsts.MARKETITEM_MARKETCURRENCYCODE]) {
this.MarketCurrencyCode = jsonObject[StoreJSONConsts.MARKETITEM_MARKETCURRENCYCODE].str;
} else {
this.MarketCurrencyCode = "";
}
if (jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICEMICROS]) {
this.MarketPriceMicros = System.Convert.ToInt64(jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICEMICROS].n);
} else {
this.MarketPriceMicros = 0;
}
}
示例13: CompareJSONCharacterAttributes
private bool CompareJSONCharacterAttributes(JSONObject _member, JSONObject _addition)
{
Debug.Log("MEMBER: " + _member.ToString());
Debug.Log("ADD: " + _addition.ToString());
if(!_member.HasField("characterName") || !_addition.HasField("characterName"))
{
Debug.Log("One of these items isn't a JSON character representation.");
return false;
}
if(_member["characterName"].str == _addition["characterName"].str &&
_member["characterRace"].str == _addition["characterRace"].str &&
_member["characterClass"].str == _addition["characterClass"].str)
return true;
return false;
}
示例14: SendRewardMessage
public static void SendRewardMessage(JSONObject result, MyMessageScript messageScript, string initialString)
{
string rewardString = "";
if (result.HasField("money"))
{
Debug.Log("reward found!");
float money = result.GetField("money").n;
string moneyReward = String.Format(StringResources.GetLocalizedString("moneyReward"), money);
rewardString += moneyReward;
}
if (result.HasField("gems"))
{
Debug.Log("reward found!");
float gems = result.GetField("gems").n;
string gemsReward = String.Format(StringResources.GetLocalizedString("gemsReward"), gems);
rewardString += gemsReward;
}
if (result.HasField("bonus"))
{
Debug.Log("reward found!");
string bonusName = StringResources.GetLocalizedString(result.GetField("bonus").str);
string bonusReward = String.Format(StringResources.GetLocalizedString("bonusReward"), bonusName);
rewardString += bonusReward;
}
if (result.HasField("tramSkin"))
{
Debug.Log("reward found!");
rewardString += StringResources.GetLocalizedString("tramSkinReward");
}
if (result.HasField("conductorSkin"))
{
Debug.Log("reward found!");
rewardString += StringResources.GetLocalizedString("conductorSkinReward");
}
if (result.HasField("tramLives"))
{
Debug.Log("reward found!");
float tramLives = result.GetField("tramLives").n;
rewardString += String.Format(StringResources.GetLocalizedString("tramLivesReward"), tramLives);
}
if (rewardString != "")
{
initialString += rewardString;
messageScript.AddMessage(initialString);
}
}
示例15: MarketItem
/// <summary>
/// Constructor.
/// Generates an instance of <c>MarketItem</c> from a <c>JSONObject<c>.
/// </summary>
/// <param name="jsonObject">A <c>JSONObject</c> representation of the wanted
/// <c>MarketItem</c>.</param>
public MarketItem(JSONObject jsonObject)
{
string keyToLook = "";
#if UNITY_IOS && !UNITY_EDITOR
keyToLook = JSONConsts.MARKETITEM_IOS_ID;
#elif UNITY_ANDROID && !UNITY_EDITOR
keyToLook = JSONConsts.MARKETITEM_ANDROID_ID;
#endif
if (!string.IsNullOrEmpty(keyToLook) && jsonObject.HasField(keyToLook)) {
ProductId = jsonObject[keyToLook].str;
} else {
ProductId = jsonObject[JSONConsts.MARKETITEM_PRODUCT_ID].str;
}
Price = jsonObject[JSONConsts.MARKETITEM_PRICE].n;
int cOrdinal = System.Convert.ToInt32(((JSONObject)jsonObject[JSONConsts.MARKETITEM_CONSUMABLE]).n);
if (cOrdinal == 0) {
this.consumable = Consumable.NONCONSUMABLE;
} else if (cOrdinal == 1){
this.consumable = Consumable.CONSUMABLE;
} else {
this.consumable = Consumable.SUBSCRIPTION;
}
}