本文整理汇总了C#中JSONObject类的典型用法代码示例。如果您正苦于以下问题:C# JSONObject类的具体用法?C# JSONObject怎么用?C# JSONObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSONObject类属于命名空间,在下文中一共展示了JSONObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: parseData
void parseData(string data)
{
JSONObject json = new JSONObject (data);
string action = json.GetField ("action").str;
print(action + "parse data" + data);
JSONObject pos = json.GetField("position");
Single pX = Convert.ToSingle (pos.GetField ("X").str);
Single pY = Convert.ToSingle (pos.GetField ("Y").str);
Single pZ = Convert.ToSingle (pos.GetField ("Z").str);
Vector3 position = new Vector3 (pX, pY, pZ);
print ("new vector = x-" + pos.GetField ("X").str + " y-" + pos.GetField ("Y").str);
JSONObject rot = json.GetField("rotation");
Single rX = Convert.ToSingle (rot.GetField ("X").str);
Single rY = Convert.ToSingle (rot.GetField ("Y").str);
Single rZ = Convert.ToSingle (rot.GetField ("Z").str);
Single rW = Convert.ToSingle (rot.GetField ("W").str);
Quaternion rotation = new Quaternion (rX, rY, rZ, rW);
switch (action) {
case "start":
this.id = json.GetField ("id").str;
createPlayer ();
break;
case "newPlayer":
createNewClient (json.GetField ("id").str, position, rotation);
break;
case "move":
moveClient (json.GetField ("id").str, position, rotation);
break;
}
}
示例2: Update
// Update is called once per frame
void Update () {
lastQ = Input.gyro.attitude;
lastAcc = Input.acceleration;
if (Transfering) {
counter += Time.deltaTime;
if (counter > updateRate) {
counter = 0;
JSONObject json = new JSONObject ();
json.AddField ("command", "gyro");
json.AddField ("x", lastQ.x);
json.AddField ("y", lastQ.y);
json.AddField ("z", lastQ.z);
json.AddField ("w", lastQ.w);
json.AddField ("accX", lastAcc.x);
json.AddField ("accY", lastAcc.y);
json.AddField ("accZ", lastAcc.z);
communicationManager.SendJson (json);
}
}
}
示例3: AddScore
/// <summary>
/// Adds Score to database
/// </summary>
/// <param name="name"></param>
/// <param name="id"></param>
/// <param name="score"></param>
/// <returns></returns>
private IEnumerator AddScore(string name, string id, string score)
{
WWWForm f = new WWWForm();
f.AddField("ScoreID", id);
f.AddField("Name", name);
f.AddField("Point", score);
WWW w = new WWW("demo/theappguruz/score/add", f);
yield return w;
if (w.error == null)
{
JSONObject jsonObject = new JSONObject(w.text);
string data = jsonObject.GetField("Status").str;
if (data != null && data.Equals("Success"))
{
Debug.Log("Successfull");
}
else
{
Debug.Log("Fatel Error");
}
}
else
{
Debug.Log("No Internet Or Other Network Issue" + w.error);
}
}
示例4: ToVector4
public static Vector4 ToVector4(JSONObject obj) {
float x = obj["x"] ? obj["x"].f : 0;
float y = obj["y"] ? obj["y"].f : 0;
float z = obj["z"] ? obj["z"].f : 0;
float w = obj["w"] ? obj["w"].f : 0;
return new Vector4(x, y, z, w);
}
示例5: ListStorePage
public KnetikApiResponse ListStorePage(
int page = 1,
int limit = 10,
List<string> terms = null,
List<string> related = null,
bool useCatalog = true,
Action<KnetikApiResponse> cb = null
)
{
JSONObject j = new JSONObject (JSONObject.Type.OBJECT);
j.AddField ("page", page);
j.AddField ("limit", limit);
if (terms != null) {
j.AddField ("terms", JSONObject.Create(terms));
}
if (related != null) {
j.AddField ("related", JSONObject.Create(related));
}
j.AddField("useCatalog", useCatalog);
String body = j.Print ();
KnetikRequest req = CreateRequest(ListStorePageEndpoint, body);
KnetikApiResponse response = new KnetikApiResponse(this, req, cb);
return response;
}
示例6: ProcessMyGameStateResponse
private static void ProcessMyGameStateResponse(JSONObject jsonData)
{
if (jsonData.GetField ("gameStates")) {
JSONObject gameStateData = jsonData.GetField ("gameStates");
for (int i = 0; i < gameStateData.list.Count; i++) {
JSONObject gameState = gameStateData.list [i];
string access = null;
if (gameState.HasField ("access")) {
access = gameState.GetField ("access").str;
}
string data = null;
if (gameState.HasField ("data")) {
data = gameState.GetField ("data").str;
}
if (access != null && data != null) {
if (access.Equals ("private")) {
PrivateGameStateData = data;
SpilUnityImplementationBase.fireGameStateUpdated ("private");
} else if (access.Equals ("public")) {
PublicGameStateData = data;
SpilUnityImplementationBase.fireGameStateUpdated ("public");
}
}
}
}
}
示例7: accessData
void accessData(JSONObject obj)
{
switch(obj.type){
case JSONObject.Type.OBJECT:
for(int i = 0; i < obj.list.Count; i++){
string key = (string)obj.keys[i];
JSONObject j = (JSONObject)obj.list[i];
Debug.Log(key);
accessData(j);
}
break;
case JSONObject.Type.ARRAY:
foreach(JSONObject j in obj.list){
accessData(j);
}
break;
case JSONObject.Type.STRING:
Debug.Log(obj.str);
break;
case JSONObject.Type.NUMBER:
Debug.Log(obj.n);
break;
case JSONObject.Type.BOOL:
Debug.Log(obj.b);
break;
case JSONObject.Type.NULL:
Debug.Log("NULL");
break;
}
}
示例8: ToVector3
public static Vector3 ToVector3(JSONObject obj)
{
float x = obj["x"] ? obj["x"].f : 0;
float y = obj["y"] ? obj["y"].f : 0;
float z = obj["z"] ? obj["z"].f : 0;
return new Vector3(x, y, z);
}
示例9: Update
public void Update()
{
if (dataLoaded || currencyWWW == null || !currencyWWW.isDone) return;
// let's look at the results
JSONObject j = new JSONObject(currencyWWW.text);
j.GetField("list", delegate (JSONObject list) {
list.GetField("resources", delegate (JSONObject resources) {
foreach (JSONObject entry in resources.list)
{
entry.GetField("resource", delegate (JSONObject resource) {
resource.GetField("fields", delegate (JSONObject fields) {
string name;
string price;
string volume;
fields.GetField(out price, "price", "-1");
fields.GetField(out name, "name", "NONAME");
fields.GetField(out volume, "volume", "NOVOLUME");
CurrencyData data = new CurrencyData(name, price, volume);
CreateDataObject(data);
//Debug.Log("Found : " + name + " = " + float.Parse(price) + " at " + float.Parse(volume) + " sold");
});
});
}
dataLoaded = true;
});
}, delegate (string list) { //"name" will be equal to the name of the missing field. In this case, "hits"
Debug.LogWarning("no data found");
});
}
示例10: OnPlayAvariable
private void OnPlayAvariable(SocketIOEvent evt )
{
UserData player1 = CheckPlayer(evt.data.GetField("player1"));
UserData player2 = CheckPlayer(evt.data.GetField("player2"));
if( GameManager.Instance.userData.ID == player1.ID ){
Debug.Log("Player1 Ready!!");
GameManager.Instance.player = GameManager.Player.player1;
JSONObject ready = new JSONObject();
ready.AddField("id", player1.ID );
NetworkManager.Instance.Socket.Emit("READY", ready);
}else{
if( GameManager.Instance.userData.ID == player2.ID ){
Debug.Log("Player2 Ready!!");
GameManager.Instance.player = GameManager.Player.player2;
JSONObject ready = new JSONObject();
ready.AddField("id", player1.ID );
NetworkManager.Instance.Socket.Emit("READY", ready);
}else{
Debug.Log("JUST WATCH!!");
GameManager.Instance.player = GameManager.Player.guest;
}
}
oldText.text = player1.UserName;
friendText.text = player2.UserName;
}
示例11: fromJSONObject
public void fromJSONObject(JSONObject json)
{
JSONObject marketItem = json.GetField("marketItem");
JSONObject jsonProductId = marketItem.GetField("productId");
if (jsonProductId != null) {
this.productId = marketItem.GetField("productId").str;
} else {
this.productId = "";
}
JSONObject jsonIosId = marketItem.GetField ("iosId");
this.useIos = (jsonIosId != null);
if (this.useIos)
{
this.iosId = jsonIosId.str;
}
JSONObject jsonAndroidId = marketItem.GetField ("androidId");
this.useAndroid = (jsonAndroidId != null);
if (this.useAndroid)
{
this.androidId = jsonAndroidId.str;
}
this.price = marketItem.GetField ("price").f;
this.consumable = (Consumable)int.Parse(marketItem.GetField("consumable").ToString());
}
示例12: ParseFrom
public Dictionary<string, string> ParseFrom(string rawdata)
{
JSONObject jsonObj = new JSONObject(rawdata);
Dictionary<string, string> data = jsonObj.ToDictionary();
return data;
}
示例13: Buy
/// <summary>
/// Buys the purchasable virtual item.
/// Implementation in subclasses will be according to specific type of purchase.
/// </summary>
/// <param name="payload">a string you want to be assigned to the purchase. This string
/// is saved in a static variable and will be given bacl to you when the
/// purchase is completed.</param>
/// <exception cref="Soomla.Store.InsufficientFundsException">throws InsufficientFundsException</exception>
public override void Buy(string payload)
{
SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Trying to buy a " + AssociatedItem.Name + " with "
+ Amount + " pieces of " + TargetItemId);
VirtualItem item = getTargetVirtualItem ();
if (item == null) {
return;
}
JSONObject eventJSON = new JSONObject();
eventJSON.AddField("itemId", AssociatedItem.ItemId);
StoreEvents.Instance.onItemPurchaseStarted(eventJSON.print(), true);
if (!checkTargetBalance (item)) {
StoreEvents.OnNotEnoughTargetItem(StoreInfo.VirtualItems["seed"]);
return;
// throw new InsufficientFundsException (TargetItemId);
}
item.Take(Amount);
AssociatedItem.Give(1);
// We have to make sure the ItemPurchased event will be fired AFTER the balance/currency-changed events.
StoreEvents.Instance.RunLater(() => {
eventJSON = new JSONObject();
eventJSON.AddField("itemId", AssociatedItem.ItemId);
eventJSON.AddField("payload", payload);
StoreEvents.Instance.onItemPurchased(eventJSON.print(), true);
});
}
示例14: OSRICAttributeModel
public OSRICAttributeModel(RPGCharacterModel _cm, JSONObject _jo)
{
cm = _cm;
CharacterModifiers = new OSRICModifierCollection();
characterName = _jo["characterName"].str;
Str = (int)_jo["Str"].n;
Dex = (int)_jo["Dex"].n;
Con = (int)_jo["Con"].n;
Int = (int)_jo["Int"].n;
Wis = (int)_jo["Wis"].n;
Cha = (int)_jo["Cha"].n;
hitPoints = (int)_jo["hitPoints"].n;
string[] levelStr = _jo["level"].str.Split('/');
level = new int[levelStr.Length];
for(int i=0; i<levelStr.Length; i++)
level[i] = Int32.Parse(levelStr[i]);
experiencePoints = (int)_jo["experiencePoints"].n;
vision = (int)_jo["vision"].n;
move = (int)_jo["move"].n;
characterGender = OSRICConstants.GetEnum<OSRIC_GENDER>(_jo["characterGender"].str);
characterRace = OSRICConstants.GetEnum<OSRIC_RACE>(_jo["characterRace"].str);
characterClass = OSRICConstants.GetEnum<OSRIC_CLASS>(_jo["characterClass"].str);
characterAlignment = OSRICConstants.GetEnum<OSRIC_ALIGNMENT>(_jo["characterAlignment"].str);
characterState = OSRICConstants.GetEnum<OSRIC_CHARACTER_STATE>(_jo["characterState"].str);
foreach(JSONObject obj in _jo["CharacterModifiers"].list)
CharacterModifiers.Add(new OSRICCharacterModifier(obj));
}
示例15: SetResults
public void SetResults(JSONObject jsonData) {
spinDataResult = jsonData;
resultsData = jsonData.GetArray("items");
winningGold = jsonData.GetArray("wGold");
// Calculate extra data (winning type, winning count from list result items)
JSONObject extraData = SlotCombination.CalculateCombination(resultsData, GetNumLine());
winningCount = extraData.GetArray("wCount");
winningType = extraData.GetArray("wType");
//
isJackpot = jsonData.GetBoolean("isJP");
freeSpinLeft = jsonData.GetInt("frLeft");
isBigWin = jsonData.GetBoolean("bWin");
gotFreeSpin = jsonData.GetInt("frCount") > 0;
// bool[] winingItems = new bool[15];
// for (int i = 0; i < winningGold.Length; i++) {
// if (winningGold[i].Number > 0) {
// for (int j = 0; j < SlotCombination.NUM_REELS; j++) {
// winingItems[SlotCombination.COMBINATION[i, j]] = true;
// }
// }
// }
for (int i = 0; i < slotReels.Length; i++) {
slotReels[i].SetResults(new int[3] { (int)resultsData[i * 3].Number, (int)resultsData[i * 3 + 1].Number, (int)resultsData[i * 3 + 2].Number });
}
}