本文整理汇总了C#中JsonWriter.Write方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.Write方法的具体用法?C# JsonWriter.Write怎么用?C# JsonWriter.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToString
public override string ToString()
{
StringBuilder sb = new StringBuilder ();
JsonWriter writer = new JsonWriter (sb);
writer.WriteObjectStart ();
writer.WritePropertyName ("option");
writer.Write (option);
writer.WritePropertyName ("subfield");
writer.Write (subfield);
writer.WritePropertyName ("tarId");
writer.Write (tarId);
writer.WriteObjectEnd ();
return sb.ToString();
}
示例2: CreateClothes
public static void CreateClothes()
{
string[] materials = Directory.GetFiles("Assets/characters_joysoft", "*.mat", SearchOption.AllDirectories);
StringBuilder sbuilders = new StringBuilder ();
JsonWriter writer = new JsonWriter (sbuilders);
writer.WriteObjectStart ();
foreach (string material in materials)
{
//Assets/characters_joysoft/Per Texture Materials/female_hair_01_01.mat
string[] parts=material.Replace(".mat","").Split('/');
string unit=parts[parts.Length-1];
writer.WritePropertyName (unit);
int hashkey=0;
foreach(string key in defaultClothes){
if(unit.Contains(key)){
hashkey=1;
break;
}
}
writer.Write (""+hashkey);
sbuilders.Append(System.Environment.NewLine);
}
writer.WriteObjectEnd ();
UpdateClothesContent(sbuilders);
Debug.Log("**********UpdateClothesContent Finish***********");
}
示例3: Deactivate
void Deactivate()
{
state = 0;
renderer.material.color = colours[0];
StringBuilder sb = new StringBuilder();
JsonWriter writer = new JsonWriter(sb);
writer.WriteObjectStart();
writer.WritePropertyName("id");
writer.Write(id);
writer.WritePropertyName("state");
writer.Write(0);
writer.WriteObjectEnd();
monome.SendMessage("SendToSaul", sb.ToString());
}
示例4: Main
static void Main()
{
#if !DEBUG
try {
#endif
// Load all configurations and if the config file does not exist, generate a new one.
string settings_file = Path.Combine(Client.directory_app_data, "settings.dcf");
Client.config = new Config(delegate(Config current_config) {
DC_Server[] server_list = new DC_Server[1];
server_list[0] = new DC_Server {
name = "NFGaming Upload Server",
url = "http://uploads.nfgaming.com",
times_connected = 0
};
current_config.set("frmlogin.servers_list", server_list);
}, settings_file);
// Set the max connections this program is allowed to have to a HTTP server.
System.Net.ServicePointManager.DefaultConnectionLimit = Client.config.get<short>("net.default_connection_limit", 4);
Client.config.save();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmLogin());
// Run the cleanup script since the main form has been closed.
cleanup();
#if !DEBUG
} catch(Exception e) {
StringBuilder sb = new StringBuilder();
JsonWriter jw = new JsonWriter(sb);
DC_Exception exception = new DC_Exception() {
help_link = e.HelpLink,
inner_exception_message = (e.InnerException != null) ? e.InnerException.Message : null,
inner_exception_stack_trace = (e.InnerException != null)? e.InnerException.StackTrace : null,
source = e.Source,
stack_trace = e.StackTrace,
message = e.Message
};
jw.Write(exception);
string args = Utilities.base64Encode(sb.ToString());
args += " ";
args += "http://dtronix.com/dtxCrashReporter/";
System.Diagnostics.Process.Start("dtxCrashReporter.exe", args);
}
#endif
}
示例5: OnGUI
void OnGUI()
{
content = GUI.TextArea(new Rect(100, 100, 400, 100), content);
/* if (GUI.Button(new Rect(330, 60, 60, 30), "Little jasson"))
{
Debug.Log("write jsson");
TextWriter wr = new StreamWriter("students.txt");
JsonWriter jsonwr = new JsonWriter(wr);
jsonwr.IndentValue = 0;
JsonMapper.ToJson(st1, jsonwr);
jsonwr.WriteObjectStart();
JsonMapper.ToJson(st2, jsonwr);
wr.Close();
}*/
if (GUI.Button(new Rect(380, 60, 60, 30), "FX jasson"))
{
/*Классы короткая запись*/
string json = JsonFx.Json.JsonWriter.Serialize(st1);
// Debug.Log(json);
Student st3 = JsonFx.Json.JsonReader.Deserialize<Student>(json);
//Debug.Log("age " + st3.age + " count " + st3.count[5] + " name " + st3.name);
/*массив*/
JsonWriterSettings settw = new JsonWriterSettings();
settw.TypeHintName = "__type";
JsonReaderSettings settr = new JsonReaderSettings();
settr.TypeHintName = "__type";
/*пример чтоб разобраться, но либа работает только с классами нормально. */
System.Text.StringBuilder builder=new System.Text.StringBuilder();
JsonWriter wr = new JsonWriter(builder,settw);
Student[] arr = new Student[3];
arr[0] = st1;
arr[1] = st2;
arr[2] = st3;
wr.Write(arr);
System.IO.File.WriteAllText("testJSON.txt", builder.ToString());
string jsonText = System.IO.File.ReadAllText("testJSON.txt");
//Debug.Log(""+jsonText);
Student[] tempSt = JsonReader.Deserialize<Student[]>(jsonText);
content = "";
foreach( var s in tempSt)
content +="" + s.name+System.Environment.NewLine;
}
}
示例6: SaveData
/// <summary>
/// 数据存Json
/// </summary>
public void SaveData()
{
StringBuilder sb = new StringBuilder();
JsonWriter jw = new JsonWriter(sb);
jw.WriteObjectStart();
//写入玩家名称
jw.WritePropertyName("Name");
jw.Write(GlobalManager.userName);
//写入开始索引
jw.WritePropertyName("StartIndex");
jw.Write(GlobalManager.startIndex);
//写入最高分
jw.WritePropertyName("MaxScore");
jw.Write(GlobalManager.maxScore);
//写入已经完成的单词总数
jw.WritePropertyName("WordAmount");
jw.Write(GlobalManager.wordAmount);
//...
jw.WriteObjectEnd();
SaveJsonString(sb.ToString());
}
示例7: SaveJson
public static void SaveJson()
{
string filePath = Application.dataPath + @"/StringAssets/file/pos.txt";
FileInfo fileInfo = new FileInfo(filePath);
if (!File.Exists(filePath))
{
File.Delete(filePath);
}
StreamWriter sw = fileInfo.CreateText();
StringBuilder sb = new StringBuilder();
JsonWriter writer = new JsonWriter(sb);
//从场景中开始一个个的遍历
foreach (EditorBuildSettingsScene s in EditorBuildSettings.scenes)
{
if (s.enabled == true)
{
string name = s.path;
EditorApplication.OpenScene(name);
GameObject parent = GameObject.Find("PosObj");
if (parent)
{
writer.WriteArrayStart(); //开始写数据
for (int i = 0; i < parent.transform.childCount; i++)
{
Transform obj = parent.transform.GetChild(i);
writer.WriteObjectStart();
writer.WritePropertyName(obj.name);
writer.Write(obj.position.x.ToString() + "," + obj.position.y.ToString() + "," +
obj.position.z.ToString());
writer.WriteObjectEnd();
}
writer.WriteArrayEnd();
}
}
}
sw.WriteLine(sb.ToString());
sw.Close();
sw.Dispose(); //关闭文件流
AssetDatabase.Refresh(); //刷新
}
示例8: PostTest1
IEnumerator PostTest1()
{
string str = @"";
// string like this
// str = @"{""Id"":0,""IMEI"":""String"",""Phone"":""String"",""Name"":""String"",""Status"":0,""CreateTime"":""\/Date(-62135596800000+0800)\/"",""UpdateTime"":""\/Date(-62135596800000+0800)\/""}";
// write Json
JsonWriter writer = new JsonWriter();
writer.WriteObjectStart();
writer.WritePropertyName("Id");
writer.Write(0);
writer.WritePropertyName("IMEI");
writer.Write("7654321");
writer.WritePropertyName("Phone");
writer.Write("13802817183");
writer.WritePropertyName("Name");
writer.Write("bbzm");
writer.WritePropertyName("Status");
writer.Write("1");
writer.WritePropertyName("CreateTime");
writer.Write("2013-01-01");
writer.WritePropertyName("UpdateTime");
writer.Write("2013-10-10");
writer.WriteObjectEnd();
str = writer.ToString();
Debug.Log(str);
WWWForm parameter = new WWWForm();
parameter.AddField("Body", str);
WWW postRequest = new WWW(@"http://192.168.133.225:82/Client/123456?format=json", parameter);
yield return postRequest;
JsonReader read = new JsonReader(postRequest.text);
Debug.Log(postRequest.text);
Debug.Log(" ----------------- ");
while (read.Read())
{
Debug.Log(read.Token + " : " + read.Value + " : " + read.GetType().ToString());
}
Debug.Log(" ----------------- ");
}
示例9: Export
public void Export(bool run)
{
try
{
string sceneName = EditorSceneManager.GetActiveScene().name;
exportationOptions.DefaultFolder = EditorUtility.SaveFolderPanel("Please select a folder", exportationOptions.DefaultFolder, "");
if (string.IsNullOrEmpty(exportationOptions.DefaultFolder))
{
return;
}
Stopwatch watch = new Stopwatch();
watch.Start();
var jsWriter = new JsonWriter();
File.WriteAllText("Unity3D2Babylon.ini", jsWriter.Write(exportationOptions));
logs.Clear();
ReportProgress(0);
var sceneBuilder = new SceneBuilder(exportationOptions.DefaultFolder, sceneName, exportationOptions);
sceneBuilder.ConvertFromUnity();
ReportProgress(1, "Generating output file");
var outputFile = sceneBuilder.WriteToBabylonFile();
watch.Stop();
ReportProgress(1, string.Format("Exportation done in {0:0.00}s", watch.Elapsed.TotalSeconds));
EditorUtility.ClearProgressBar();
sceneBuilder.GenerateStatus(logs);
ShowMessage("Exportation done");
if (run)
{
WebServer.SceneFolder = Path.GetDirectoryName(outputFile);
WebServer.SceneFilename = Path.GetFileName(outputFile);
Process.Start("http://localhost:" + WebServer.Port);
}
}
catch (Exception ex)
{
EditorUtility.ClearProgressBar();
ShowMessage("A problem occurred: " + ex.Message + ex.StackTrace, "Error");
}
}
示例10: WriteJsonAndPrint
void WriteJsonAndPrint()
{
System.Text.StringBuilder strB = new System.Text.StringBuilder();
JsonWriter jsWrite = new JsonWriter(strB);
jsWrite.WriteObjectStart();
jsWrite.WritePropertyName("Name");
jsWrite.Write("taotao");
jsWrite.WritePropertyName("Age");
jsWrite.Write(25);
jsWrite.WritePropertyName("MM");
jsWrite.WriteArrayStart();
jsWrite.WriteObjectStart();
jsWrite.WritePropertyName("name");
jsWrite.Write("xiaomei");
jsWrite.WritePropertyName("age");
jsWrite.Write("17");
jsWrite.WriteObjectEnd();
jsWrite.WriteObjectStart();
jsWrite.WritePropertyName("name");
jsWrite.Write("xiaoli");
jsWrite.WritePropertyName("age");
jsWrite.Write("18");
jsWrite.WriteObjectEnd();
jsWrite.WriteArrayEnd();
jsWrite.WriteObjectEnd();
Debug.Log(strB);
JsonData jd = JsonMapper.ToObject(strB.ToString());
Debug.Log("name=" + jd["Name"]);
Debug.Log("age=" + jd["Age"]);
JsonData jdItems = jd["MM"];
for (int i = 0; i < jdItems.Count; i++)
{
Debug.Log("MM name=" + jdItems["name"]);
Debug.Log("MM age=" + jdItems["age"]);
}
}
示例11: ExportParameterFile
private void ExportParameterFile()
{
// Output the settings to INI for viewing.
var outParamName = Path.GetFileNameWithoutExtension(m_config.ParameterFile);
if (outParamName == null)
return;
var outParamPath = Path.Combine(m_config.AnalysisPath, outParamName);
var writer = new JsonWriter<MultiAlignAnalysisOptions>();
writer.Write(outParamPath + ".json", m_config.Analysis.Options);
}
示例12: SaveLocal
public void SaveLocal()
{
var charWriter = new JsonWriter(new JsonFx.Serialization.DataWriterSettings(new JsonFx.Json.Resolvers.JsonResolverStrategy()));
var charData = charWriter.Write(Characters);
var filePath = Application.dataPath + @"/Data/save.json";
using (var saveFile = new StreamWriter(filePath))
{
saveFile.Write(charData);
}
}
示例13: ExportScenesToJSON
public static void ExportScenesToJSON()
{
string path = EditorUtility.SaveFilePanel("SaveJason", Application.dataPath, "Scenes_Config_JSON", "txt");
FileInfo fileInfo = new FileInfo(path);
StreamWriter sw = fileInfo.CreateText();
StringBuilder sb = new StringBuilder();
JsonWriter writer = new JsonWriter(sb);
writer.WriteObjectStart();
writer.WritePropertyName("root");
writer.WriteArrayStart();
foreach (EditorBuildSettingsScene S in EditorBuildSettings.scenes)
{
if (S.enabled)
{
EditorApplication.OpenScene(S.path);
writer.WriteObjectStart();
writer.WritePropertyName("Scene");
writer.WriteArrayStart();
writer.WriteObjectStart();
writer.WritePropertyName("SceneName");
writer.Write(S.path);
writer.WritePropertyName("GameObjects");
writer.WriteArrayStart();
foreach (GameObject obj in Object.FindObjectsOfType(typeof(GameObject)))
{
if (obj.transform.parent == null)
{
writer.WriteObjectStart();
writer.WritePropertyName("GameObjectName");
writer.Write(obj.name);
writer.WritePropertyName("Position");
writer.WriteArrayStart();
writer.WriteObjectStart();
writer.WritePropertyName("X");
writer.Write(obj.transform.position.x.ToString("F5"));
writer.WritePropertyName("Y");
writer.Write(obj.transform.position.y.ToString("F5"));
writer.WritePropertyName("Z");
writer.Write(obj.transform.position.z.ToString("F5"));
writer.WriteObjectEnd();
writer.WriteArrayEnd();
writer.WritePropertyName("Rotation");
writer.WriteArrayStart();
writer.WriteObjectStart();
writer.WritePropertyName("X");
writer.Write(obj.transform.rotation.eulerAngles.x.ToString("F5"));
writer.WritePropertyName("Y");
writer.Write(obj.transform.rotation.eulerAngles.y.ToString("F5"));
writer.WritePropertyName("Z");
writer.Write(obj.transform.rotation.eulerAngles.z.ToString("F5"));
writer.WriteObjectEnd();
writer.WriteArrayEnd();
writer.WritePropertyName("Scale");
writer.WriteArrayStart();
writer.WriteObjectStart();
writer.WritePropertyName("X");
writer.Write(obj.transform.localScale.x.ToString("F5"));
writer.WritePropertyName("Y");
writer.Write(obj.transform.localScale.y.ToString("F5"));
writer.WritePropertyName("Z");
writer.Write(obj.transform.localScale.z.ToString("F5"));
writer.WriteObjectEnd();
writer.WriteArrayEnd();
writer.WriteObjectEnd();
}
}
writer.WriteArrayEnd();
writer.WriteObjectEnd();
writer.WriteArrayEnd();
writer.WriteObjectEnd();
}
}
writer.WriteArrayEnd();
writer.WriteObjectEnd();
sw.WriteLine(sb.ToString());
sw.Close();
sw.Dispose();
AssetDatabase.Refresh();
}
示例14: toJson
public virtual String toJson()
{
var writer = new JsonWriter();
return writer.Write(this);
}
示例15: PostURL
/// <summary>
/// Post to a a URL endpoint with required field(s) and gives an optional response handler.
/// </summary>
/// <param name="url">The URL to post to.</param>
/// <param name="responseHandler">An Action that handles the response (optional).</param>
public void PostURL(string url, Dictionary<string, object> fields, Action<Dictionary<string, object>> responseHandler=null) {
// Kill networking immediately if no connection
// if(Application.internetReachability == NetworkReachability.NotReachable)
// KillNetwork(true);
if(_ignoreNetwork) {
fields.Add("local", true);
responseHandler(fields);
return;
}
string absoluteURL = DataManager.RemoteURL + url;
// Send form as raw byte array
System.Text.StringBuilder output = new System.Text.StringBuilder();
JsonWriter writer = new JsonWriter (output);
if(_sessionCookie != null)
fields.Add("sessionID", System.Convert.ChangeType(_sessionCookie, typeof(object)));
// If no session cookie, client has no auth, so cache this request to do later
else if(url != "/auth/") {
PostCache cacheObj = new PostCache();
cacheObj.url = url;
cacheObj.fields = fields;
cacheObj.responseHandler = responseHandler;
_cachedRequests.Add(cacheObj);
return;
}
writer.Write(fields);
// Encode output as UTF8 bytes
_currentRoutine = WaitForForm(absoluteURL, Encoding.UTF8.GetBytes(output.ToString()), responseHandler);
StartCoroutine(_currentRoutine);
}