我构建了一个导航树,并在数组中使用此函数保存结构
function parseTree(html) {
var nodes = [];
html.parent().children("div").each(function () {
var subtree = $(this).children("div");
var item = $(this).find(">span");
if (subtree.size() > 0)
nodes.push([item.attr("data-pId"), item.attr("data-id"), parseTree(subtree)]);
else
nodes.push(item.attr("data-pId"), item.attr("data-id"));
});
return nodes;
}
Run Code Online (Sandbox Code Playgroud)
然后我序列化数据
var tree = $.toJSON(parseTree($("#MyTree").children("div")));
Run Code Online (Sandbox Code Playgroud)
获取此数组
[
["881150024","881150024",
[
"994441819","881150024",
"214494418","881150024"
]
],
["-256163399","-256163399",
[
"977082012","-256163399",
"-492694206","-256163399",
[
"1706814966","-256163399",
["-26481618","-256163399"]
]
]
]
]
Run Code Online (Sandbox Code Playgroud)
并通过ajax发送
$.ajax({
url: "Editor/SerializeTree",
type: "POST",
data: { tree: tree },
success: function (result) {
alert("OK");
}
});
Run Code Online (Sandbox Code Playgroud)
问题:如何在C#中使用JavaScriptSerializer反序列化此JSON?
如何在 TypeScript 中为这样的数组定义类型:
export const AlternativeSpatialReferences: Array< ??? > = [
{
'25833': 25833
},
{
'25832': 25832
},
{
'25831': 25831
},
{
'Google': 4326
}
];
Run Code Online (Sandbox Code Playgroud)
现在我只使用 Array<{}>,但想要正确定义。
我有这种代码和平.我必须检查XML中的每个级别,避免NULL异常.我可以改进这段代码吗?
private void GetFunctionsValues(XElement x)
{
if (x.Element("credentials") != null)
{
if (x.Element("credentials").Element("faccess") != null)
{
foreach (var access in x.Element("credentials").Element("faccess").Elements("access"))
{
if (access.Attribute("db_id") != null)
{
if (int.Parse(access.Attribute("db_id").Value) == 19) FuncPlus = true;
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有这样的字符串
"<root><text>My test is > & < </text></root>"
Run Code Online (Sandbox Code Playgroud)
实际上这是正确的xml,除了&,<,>符号.
我需要将它转换为<root><text>My test is > & < </text></root>我用XElement.Parse(str)转换它之前;
如何进行此转换?
我有一个例子:
<table class="border" style="width:100%">
<tr>
<td style="width:30%" class="border p10">
Test
</td>
<td style="width:70%" class="border p10">
<p class="longText">
Looong text Looong text Looong text Looong text Looong text Looong text Looong text Looong text
</p>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
CSS:
.longText {
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
width:100%
}
.border {border: solid 1px #ccc}
.p10 {padding: 10px}
Run Code Online (Sandbox Code Playgroud)
你可以在这里试试http://jsfiddle.net/rnwCw/20/
问题是长文本会破坏细胞的宽度(30%和70%).如果我将.longText的宽度设置为PX,例如200px,那么表格就可以了.但我需要<P>占用100%的细胞.如何解决这个问题呢?
我有像这样的xml
<root>
<text>My test is 5 > 2 & 10 < 12</text>
</root>
Run Code Online (Sandbox Code Playgroud)
当我将其转换为xElement时
var xe = XElement.Parse(xml);
Run Code Online (Sandbox Code Playgroud)
我收到错误
如果xml内容&我收到此错误«解析EntityName时出错»
如果xml内容>所以我得到此错误«名称不能以'<'字符开头,十六进制值0x3C.»
有一个字符串
str = "test--removing-----minus-";
Run Code Online (Sandbox Code Playgroud)
试图替换
str = Regex.Replace(str, @"\-*", @"-");
Run Code Online (Sandbox Code Playgroud)
但我明白了
"t-e-s-t--r-e-m-o-v-i-n-g--m-i-n-u-s-";
Run Code Online (Sandbox Code Playgroud) c# ×5
regex ×2
xml ×2
xml-parsing ×2
arrays ×1
css ×1
html ×1
html-table ×1
html5 ×1
if-statement ×1
json ×1
replace ×1
typescript ×1
xelement ×1
xhtml ×1