public override void ToObject(string json, bool isResData) { RecvDataT obj; try { if (isResData) { WebAPIJsonParse.GetResponseData <RecvDataT>(WebAPIJsonParse.GetBody(json), out obj); } else { WebAPIJsonParse.GetResponseData <RecvDataT>(json, out obj); } } catch (JsonException ex) { throw new WebAPIException(WWWResponse.LocalErrorStatus.LOCAL_ERROR_JSONPARSE, ex.Message); } if (this.OnReceived != null) { this.OnReceived(obj); } this.SetHeader(json); }
public IEnumerator Exceution(WebAPI webApi) { string sendJson = WebAPIJsonParse.CreateJsonData(this.requestList); WWWResponse response = new WWWResponse(); yield return(webApi.StartCoroutine(GameWebAPI.Instance().StartAPIRequest("API List", sendJson, response))); try { string responseJson = GameWebAPI.Instance().GetResponseJson(response); try { Dictionary <string, string> responseList = WebAPIJsonParse.GetResponseList(this.requestList, responseJson); for (int i = 0; i < this.requestList.Count; i++) { if (responseList.ContainsKey(this.requestList[i].apiId)) { this.requestList[i].ToObject(responseList[this.requestList[i].apiId], false); } } } catch (JsonException ex) { throw new WebAPIException(WWWResponse.LocalErrorStatus.LOCAL_ERROR_JSONPARSE, ex.Message); } } catch (WebAPIException ex2) { throw ex2; } yield break; }
public static string GetBody(string json) { string result; try { int num = json.IndexOf("resData"); num = json.IndexOf(":", num); num++; if ("null" == json.Substring(num, "null".Length)) { result = string.Empty; } else { num = json.IndexOf(":", num); num++; int num2 = WebAPIJsonParse.SkipBody(json, num + 1); string text = json.Substring(num, num2 - num); if ("null" == text.Substring(0, "null".Length)) { result = string.Empty; } else { result = text.Trim(); } } } catch (Exception ex) { throw new JsonException(ex.ToString()); } return(result); }
public string GetResponseJson(WWWResponse request_result) { if (request_result.errorStatus != WWWResponse.LocalErrorStatus.NONE) { throw new WebAPIException(request_result.errorStatus, request_result.errorText); } try { this.DEBUG_LOG("==================================== API RESPONCE JSON = " + request_result.responseJson); int @int = WebAPIJsonParse.GetInt(request_result.responseJson, "venus_status"); if (@int == -1) { throw new WebAPIException(WWWResponse.LocalErrorStatus.LOCAL_ERROR_JSONPARSE, "Not Found venus_status"); } switch (@int) { case 1: return(request_result.responseJson); case 2: case 6: case 11: throw new WebAPIException(this.GetResponseError(request_result.responseJson)); } throw new WebAPIException(this.GetResponseError(request_result.responseJson)); } catch (JsonException ex) { throw new WebAPIException(WWWResponse.LocalErrorStatus.LOCAL_ERROR_JSONPARSE, ex.Message); } string result; return(result); }
public static Dictionary <string, string> GetResponseList(List <RequestBase> requestList, string json) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(json)) { int num = json.IndexOf("resData"); if (num == -1) { throw new JsonException("json parse error : GetJsonData"); } while (json.Length > num && json[num] != '{') { num++; } num++; while (json.Length > num) { int num2 = num; while (json.Length > num2 && json[num2] != '{') { num2++; } if (json.Length <= num2) { break; } for (int i = dictionary.Count; i < requestList.Count; i++) { int num3 = json.IndexOf("null", num, num2 - num); if (num3 != -1) { dictionary.Add(requestList[i].apiId, string.Empty); num = num3 + "null".Length; } } for (int j = dictionary.Count; j < requestList.Count; j++) { if (json.IndexOf(requestList[j].apiId, num, num2 - num) != -1) { int num4 = WebAPIJsonParse.SkipBody(json, num2 + 1); dictionary.Add(requestList[j].apiId, json.Substring(num2, num4 - num2).Trim()); num = num4; break; } } if (num2 == num) { num = WebAPIJsonParse.SkipBody(json, num2 + 1); global::Debug.LogWarning("WebAPIJsonParse.GetResponseList : Not Found Response"); } } } return(dictionary); }
public IEnumerator Exceution(WebAPI webApi, WebAPI.RequestStatus requestStatus) { this.param.requestStatus = (int)requestStatus; string sendJson = WebAPIJsonParse.CreateJsonData(this.apiId, this.param); WWWResponse response = new WWWResponse(); yield return webApi.StartCoroutine(webApi.StartAPIRequest(this.apiId, sendJson, response)); try { string responseJson = webApi.GetResponseJson(response); this.ToObject(responseJson, true); } catch (WebAPIException ex) { if (ex != null) { ex.apiId = this.apiId; } throw ex; } yield break; }
private static int SkipBody(string json, int startScope) { int num = 1; int num2 = startScope; while (0 < num) { int i = num2; while (json.Length > i) { if (json[i] == '"') { i = WebAPIJsonParse.SkipString(json, i); } if (json[i] == '}') { break; } i++; } if (json.Length <= i) { throw new JsonException("json parse error : SkipBody"); } num--; while (i >= num2) { if (json[num2] == '"') { num2 = WebAPIJsonParse.SkipString(json, num2); } if (json[num2] == '{') { num++; } num2++; } } return(num2); }