从JSON
生成TCL
输出的最佳方法是什么?您建议使用哪些数据结构来创建TCL
数据,以及您将使用哪些JSON
库(请尽可能保持标准)?
{
"return_block": {
"error_text": "0",
"party_response_list": {
"party_561": {"num": 228},
"party_5037": {"num": 98}
},
"app_response_list": {
"app_8141": {"num": 228},
"app_9009": {"num": 98}
}
}
}
答案 0 :(得分:3)
目前推荐的Tcl最新JSON库是rl_json
,它有详细记录,快速而强大。它的设计目的是能够扩展到非常大型文档。
package require rl_json
# Simple write the value into a Tcl variable
set errTxt "0"
# Build a composite JSON value; perfect for iteration out of a DB…
set parties {}
json set parties "party_561" "num" 228
json set parties "party_5037" "num" 98
# Another example, this time with actual iteration…
set apps {}
foreach {id num} {app_8141 228 app_9009 98} {
json set apps $id "num" $num
}
# Build the overall doc and print it; note the interpolations of strings and JSON sub-documents
puts [json template {
{"return_block": {
"error_text": "~S:errTxt",
"party_response_list": "~J:parties",
"app_response_list": "~J:apps"
}}
}]
请注意,您需要明确您在关键位置所做的事情;图书馆并没有试图猜测事物的类型。 (另外,你可以使用大量的json set
来电,但这很麻烦。)
答案 1 :(得分:1)
Tcl"标准库"称为img.DataContext = new YourClass();
...
public class YourClass : INotifyPropertyChanged
{
private bool _attachStat;
public bool AttachStat
{
get
{
return _attachStat;
}
set
{
_attachStat = value;
NotifyPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
(这是一套外部软件包,但它适用于任何合理的操作系统)provides tcllib
和json
软件包。