示例#1
0
        protected static void SendJson(object data)
        {
            var writer = new JsonWriter();

            if (Options.ContainsKey("pp") && !Options.ContainsKey("1l"))
            {
                writer.IndentValue = 2;
                writer.PrettyPrint = true;
            }

            JsonMapper.RegisterExporter <float>((o, w) => w.Write(Convert.ToDouble(o)));

            var f = Options.ContainsKey("strpos") ? "S" : Options.ContainsKey("worldpos") ? "W" : Options.ContainsKey("csvpos") ? "C" : "V";

            JsonMapper.RegisterExporter <Vector3>((v, w) => BCUtils.WriteVector3(v, w, f));
            JsonMapper.RegisterExporter <Vector3i>((v, w) => BCUtils.WriteVector3i(v, w, f));

            var jsonOut = new Dictionary <string, object>();

            if (Options.ContainsKey("tag"))
            {
                jsonOut.Add("tag", Options["tag"]);
                jsonOut.Add("data", data);

                JsonMapper.ToJson(jsonOut, writer);
            }
            else
            {
                JsonMapper.ToJson(data, writer);
            }

            SendOutput(writer.ToString().TrimStart());
        }