This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SerializableApiAvatar.cs
108 lines (95 loc) · 3.66 KB
/
SerializableApiAvatar.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
namespace VRCTools
{
[Serializable]
public class SerializableApiAvatar
{
public string id;
public string name;
public string imageUrl;
public string authorName;
public string authorId;
public string assetUrl;
public string description;
public string[] tags;
public double version;
public string unityPackageUrl;
public string thumbnailImageUrl;
public SerializableApiAvatar(string id, string name, string imageUrl, string authorName, string authorId, string assetUrl, string description, List<string> tags, int version, string unityPackageUrl, string thumbnailImageUrl)
{
this.id = id;
this.name = name;
this.imageUrl = imageUrl;
this.authorName = authorName;
this.authorId = authorId;
this.assetUrl = assetUrl;
this.description = description;
this.tags = tags.ToArray();
this.version = version;
this.unityPackageUrl = unityPackageUrl;
this.thumbnailImageUrl = thumbnailImageUrl;
}
public Dictionary<string, object> getDictionary()
{
Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("id", id);
dic.Add("name", name);
dic.Add("imageUrl", imageUrl);
dic.Add("authorName", authorName);
dic.Add("authorId", authorId);
dic.Add("assetUrl", assetUrl);
dic.Add("description", description);
List<object> tagList = new List<object>();
tagList.AddRange(tags);
dic.Add("tags", tagList);
dic.Add("version", version);
dic.Add("unityPackageUrl", unityPackageUrl);
dic.Add("thumbnailImageUrl", thumbnailImageUrl);
dic.Add("releaseStatus", "public");
return dic;
}
public static List<SerializableApiAvatar> ParseJson(String json)
{
List<SerializableApiAvatar> saa = new List<SerializableApiAvatar>();
string parts = json.Substring(9);
parts = parts.Substring(0, parts.Length-2);
MatchCollection matches = Regex.Matches(parts, @"({.+?})");
foreach(Match m in matches)
{
saa.Add(JsonUtility.FromJson<SerializableApiAvatar>(m.Value));
//saa.Add(BestHTTP.JSON.Json.Decode(m.Value) as SerializableApiAvatar);
}
return saa;
}
public string AsJson()
{
string tagsS = "[";
bool first = true;
foreach(string tag in tags)
{
if (!first) tagsS += ",";
tagsS += "\"" + tag + "\"";
first = false;
}
tagsS += "]";
string jsonString =
"{" +
"\"id\":\"" + id + "\"," +
"\"name\":\"" + name + "\"," +
"\"imageUrl\":\"" + imageUrl + "\"," +
"\"authorName\":\"" + authorName + "\"," +
"\"authorId\":\"" + authorId + "\"," +
"\"assetUrl\":\"" + assetUrl + "\"," +
"\"description\":\"" + description + "\"," +
"\"tags\":" + tagsS + "," +
"\"version\":\"" + version + "\"," +
"\"unityPackageUrl\":\"" + unityPackageUrl + "\"," +
"\"thumbnailImageUrl\":\"" + thumbnailImageUrl + "\"" +
"}";
return jsonString;
}
}
}