Skip to content

Commit dde2200

Browse files
committed
add json lib
1 parent c1515da commit dde2200

9 files changed

Lines changed: 121 additions & 10 deletions

Assets/Others/Json.meta

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

Assets/Others/Json/JsonNet-Lite.meta

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Id": "JsonNet-Lite",
3+
"Version": "9.0.1",
4+
"Authors": [
5+
"James Newton-King"
6+
],
7+
"Owners": [
8+
"Esun Kim"
9+
],
10+
"Description": "Unity3D port of Json.NET which is a popular high-performance JSON framework for .NET",
11+
"Files": [
12+
"Assets/UnityPackages/JsonNet-Lite/Newtonsoft.Json.dll",
13+
"Assets/UnityPackages/JsonNet-Lite/Newtonsoft.Json.dll.mdb"
14+
]
15+
}

Assets/Others/Json/JsonNet-Lite.unitypackage.json.meta

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
249 KB
Binary file not shown.
98.6 KB
Binary file not shown.

Assets/Others/Json/JsonNet-Lite/Newtonsoft.Json.dll.mdb.meta

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

Assets/Others/Json/JsonNet-Lite/Newtonsoft.Json.dll.meta

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections;
34
using System.Collections.Generic;
45
using System.Web;
56
using UnityEngine;
67
using UnityEngine.Networking;
78
using UnityEngine.SceneManagement;
89

10+
public class StatRecord
11+
{
12+
public string phone_type;
13+
public string android_version;
14+
public int app_version;
15+
public int enter_scene;
16+
}
17+
18+
public class StatRsp
19+
{
20+
public int code;
21+
public List<StatRecord> data;
22+
}
23+
924
public class SupportPhoneStat : MonoBehaviour
10-
{
25+
{
26+
static readonly string HOST = "http://noodle1983.gz01.bdysite.com";
27+
static SupportPhoneStat instance;
28+
29+
public delegate void OnResponse(StatRsp rsp);
30+
1131
// Start is called before the first frame update
1232
void Start()
1333
{
14-
StartCoroutine(ReportEnterScene());
15-
34+
instance = this;
35+
StartCoroutine(ReportEnterScene());
1636
}
1737

1838
IEnumerator ReportEnterScene()
@@ -24,18 +44,16 @@ IEnumerator ReportEnterScene()
2444
int appVersion = 1;
2545
int random = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
2646

27-
string url = "http://noodle1983.gz01.bdysite.com/index.php/PatchRecord/login?";
47+
string url = HOST + "/index.php/PatchRecord/login?";
2848
string param = "phone_id=" + Uri.EscapeDataString(phoneId)
2949
+ "&phone_type=" + Uri.EscapeDataString(phoneType)
3050
+ "&android_version=" + Uri.EscapeDataString(androidVersion)
3151
+ "&enter_scene=" + sceneNumber
3252
+ "&app_version=" + appVersion
3353
+ "&rand=" + random;
3454
string req = url + param;
35-
Debug.Log(req);
3655

3756
UnityWebRequest www = UnityWebRequest.Get(req);
38-
www.SetRequestHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36");
3957
yield return www.SendWebRequest();
4058

4159
if (www.isNetworkError || www.isHttpError)
@@ -44,11 +62,32 @@ IEnumerator ReportEnterScene()
4462
}
4563
else
4664
{
47-
// Show results as text
4865
Debug.Log(www.downloadHandler.text);
66+
}
67+
GetSupportedStat((rsp) => { if (rsp != null) { Debug.Log(JsonConvert.SerializeObject(rsp)); } });
68+
}
69+
70+
public static void GetSupportedStat(OnResponse onRsp)
71+
{
72+
if (instance == null) { onRsp(null); return; }
73+
instance.StartCoroutine(FetchSupportedStat(onRsp));
74+
}
75+
76+
static IEnumerator FetchSupportedStat(OnResponse onRsp)
77+
{
78+
string req = HOST + "/index.php/PatchRecord/dump_stat";
79+
UnityWebRequest www = UnityWebRequest.Get(req);
80+
yield return www.SendWebRequest();
4981

50-
// Or retrieve results as binary data
51-
byte[] results = www.downloadHandler.data;
82+
if (www.isNetworkError || www.isHttpError)
83+
{
84+
Debug.Log(www.error);
85+
onRsp(null);
86+
yield break;
5287
}
88+
89+
Debug.Log(www.downloadHandler.text);
90+
StatRsp rsp = JsonConvert.DeserializeObject<StatRsp>(www.downloadHandler.text);
91+
onRsp(rsp);
5392
}
5493
}

0 commit comments

Comments
 (0)