本文整理汇总了C#中Dictionary.ToJSON方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.ToJSON方法的具体用法?C# Dictionary.ToJSON怎么用?C# Dictionary.ToJSON使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.ToJSON方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: json
public static HttpContent json(HttpRequest request)
{
try
{
var result = new Dictionary<string, object>();
result.Add("request", Encoding.ASCII.GetString(request.Data));
result.Add("guid", Guid.NewGuid().ToString());
result.Add("html", @"<h1 class=""page-header"">" + request.Data + @"</h1><br/>" );
if (Encoding.ASCII.GetString(request.Data) == "error") throw new ApplicationException("error test");
return new HttpContent(result.ToJSON());
}
catch (Exception ex)
{
return new HttpErrorContent(ex);
}
}
示例2: BuildSemantics
public static string BuildSemantics(IDictionary<string, object> semantics)
{
var strings = new Dictionary<string, string>();
foreach (var entry in semantics)
{
if (entry.Value == null)
continue;
var type = entry.Value.GetType();
if (type == typeof(string))
strings.Add(entry.Key, entry.Value as string);
#if NETFX
else if (type.IsEnum)
#elif UNIVERSAL
else if (type.GetTypeInfo().IsEnum)
#endif
strings.Add(entry.Key, ((int)entry.Value).ToStringInvariant());
else if (type.IsNumber())
strings.Add(entry.Key, entry.ToStringInvariant());
else
strings.Add(entry.Key, entry.Value.ToJSON());
}
return strings.ToJSON(HtmlEncode: false);
}
示例3: Main
static void Main(string[] args)
{
string a = "hello", b = "bye";
Console.WriteLine(a.GreaterThan(b));
int[] array = { 1, 2, 3, 4 };
Console.WriteLine(array.Implode());
Console.WriteLine(array.ToJSON());
List<int> list = new List<int>() { 5, 6, 7, 8 };
Console.WriteLine(list.Implode());
Console.WriteLine(list.ToJSON());
Dictionary<int, string> dict = new Dictionary<int, string>();
dict.Add(3, "three");
dict.Add(5, "five");
Console.WriteLine(dict.ToJSON());
TestClass test = new TestClass("Andrew", new int[] { 1, 2, 3 }, 13);
Console.WriteLine(test.ToJSON());
Console.ReadKey();
}
示例4: LastSnapshotId
public string LastSnapshotId()
{
Dictionary<String, Guid> result = new Dictionary<string, Guid>();
result.Add(RESULT, ServerContextSingleton.Instance.ServerContext.LastSnapshotId());
return result.ToJSON();
}
示例5: GetRootType
public string GetRootType()
{
Type rootType = ServerContextSingleton.Instance.ServerContext.GetRootType();
TypeMetadata root = TypeSingleton.ExtractTypeMetadata(rootType);
Dictionary<String, TypeMetadata> result = new Dictionary<string, TypeMetadata>();
result.Add(RESULT, root);
return result.ToJSON();
}
示例6: GetRootObjectId
public string GetRootObjectId(string snapshotId)
{
Guid snapshotIdParsed = Guid.Parse(snapshotId);
Guid rootId = ServerContextSingleton.Instance.ServerContext.GetRootObjectId(snapshotIdParsed);
Dictionary<String, Guid> result = new Dictionary<string, Guid>();
result.Add(RESULT, rootId);
return result.ToJSON();
}
示例7: GetNode
public string GetNode(string nodeId, int access)
{
Guid nodeGuid = Guid.Parse(nodeId);
NodeAccess nodeAccess = (NodeAccess)access;
Dictionary<String, NodeWrapper> result = new Dictionary<string, NodeWrapper>();
var node = ServerContextSingleton.Instance.ServerContext.GetNode(nodeGuid, nodeAccess);
var nodeWraped = NodeWrapper.TransformeNode(node);
result.Add(RESULT, nodeWraped);
return result.ToJSON();
}
示例8: EnumerateNodes
public string EnumerateNodes()
{
Dictionary<String, System.Collections.IEnumerable> result = new Dictionary<string, System.Collections.IEnumerable>();
result.Add(RESULT, ServerContextSingleton.Instance.ServerContext.EnumerateNodes());
return result.ToJSON();
}
示例9: DefaultWorkspaceTimeout
public string DefaultWorkspaceTimeout()
{
Dictionary<String, long> result = new Dictionary<string, long>();
result.Add(RESULT, ServerContextSingleton.Instance.ServerContext.DefaultWorkspaceTimeout.Ticks);
return result.ToJSON();
}
示例10: Contains
public string Contains(string identifier)
{
Guid id = Guid.Parse(identifier);
Dictionary<String, Boolean> result = new Dictionary<string, Boolean>();
result.Add(RESULT, ServerContextSingleton.Instance.ServerContext.Contains(id));
return result.ToJSON();
}
示例11: Commit
public string Commit(string workspaceId, object changeSet)
{
Guid guidWorkspaceId = Guid.Parse(workspaceId);
//transform changeSet into IsolatedChangeSet object
IsolatedChangeSet<Guid, object, EdgeData> serverChangeSet = ChangeSetParser.Parse(changeSet);
//commit changes
CommitResult<Guid> commitResult =
ServerContextSingleton.Instance.ServerContext.Commit(guidWorkspaceId, serverChangeSet);
String resultSnapshotId = commitResult.ResultSnapshotId.ToString();
Dictionary<string, string> mapping = new Dictionary<string, string>();
foreach (KeyValuePair<Guid, Guid> mapObject in commitResult.Mapping)
{
mapping.Add(mapObject.Key.ToString(), mapObject.Value.ToString());
}
CommitResult<String> commitResultString = new CommitResult<string>(resultSnapshotId, mapping);
Dictionary<String, CommitResult<String>> rez = new Dictionary<string, CommitResult<string>>();
rez.Add(RESULT, commitResultString);
return rez.ToJSON();
}
示例12: Button6Click
void Button6Click(object sender, EventArgs e)
{
var data = @"\tC:\\test\\ \n";
data = Regex.Replace(data, @"([^\\]|^)([\\][n])", m => m.Groups[1].Value + "\n");
data = Regex.Replace(data, @"([^\\]|^)([\\][t])", m => m.Groups[1].Value + "\t");
data = Regex.Replace(data, @"([^\\]|^)([\\][\\])", m => m.Groups[1].Value + "\\");
System.Diagnostics.Debug.WriteLine(data);
var json = new Dictionary<string, object>();
json.Add("test", @"c:\test\ 102/103 ""abc efg""");
var jsonString = json.ToJSON();
var decodeJsonString = jsonString.GetJSON("test", "abc");
json = new Dictionary<string, object>();
json.Add("test", decodeJsonString);
var jsonString2 = json.ToJSON();
System.Diagnostics.Debug.WriteLine(jsonString);
System.Diagnostics.Debug.WriteLine(jsonString2);
}
示例13: WriteConfig
static bool WriteConfig()
{
try
{
var config = new Dictionary<Type, ThingConfig>();
foreach (var kv in Lookup)
{
var pinConf = kv.Key.Config.Find(cp => cp.Name == "Pin").Value;
var sensor = kv.Value;
config.Add(sensor.GetType(), new ThingConfig() { Pin = pinConf, Period = (int)sensor.Watcher.SamplingPeriod });
}
File.WriteAllText(ThingsConfFileName, config.ToJSON());
return true;
}
catch (Exception ex)
{
DebugEx.TraceErrorException(ex);
return false;
}
}
示例14: ReadConfig
static Dictionary<Type, ThingConfig> ReadConfig()
{
Dictionary<Type, ThingConfig> config = null;
try
{
if (File.Exists(ThingsConfFileName))
{
var content = File.ReadAllText(ThingsConfFileName);
//deserialize into List of Configurations and pick the active one
config = content.FromJSON<Dictionary<Type, ThingConfig>>();
}
}
catch (Exception ex)
{
DebugEx.TraceErrorException(ex);
}
if (config == null)
{
config = new Dictionary<Type, ThingConfig>()
{
{ typeof(GPIO), new ThingConfig() { Pin = "", Period = 100 } },
{ typeof(Buzzer), new ThingConfig() { Pin = "D7", Period = 0 } },
{ typeof(RgbLed), new ThingConfig() { Pin = "D4", Period = 0 } },
{ typeof(SoundSensor), new ThingConfig() { Pin = "A2", Period = 1000 } },
{ typeof(LightSensor), new ThingConfig() { Pin = "A1", Period = 500 } },
{ typeof(Button), new ThingConfig() { Pin = "D2", Period = 200 } },
{ typeof(RotaryAngleSensor), new ThingConfig() { Pin = "A0", Period = 200 } },
{ typeof(Relay), new ThingConfig() { Pin = "D3", Period = 1000 } },
{ typeof(TempAndHumidity), new ThingConfig() { Pin = "D6", Period = 500 } },
{ typeof(UltraSonicRanger), new ThingConfig() { Pin = "D8", Period = 100 } },
{ typeof(LCD), new ThingConfig() { Pin = "I2C", Period = 0 } },
};
try
{
File.WriteAllText(ThingsConfFileName, config.ToJSON());
}
catch (Exception ex) { DebugEx.TraceErrorException(ex); }
}
return config;
}
示例15: SnapshotIsolationEnabled
public string SnapshotIsolationEnabled()
{
Dictionary<String, Boolean> result = new Dictionary<string, Boolean>();
result.Add(RESULT, ServerContextSingleton.Instance.ServerContext.SnapshotIsolationEnabled);
return result.ToJSON();
}