我的下一个JObject:如何提取JArray一定的价值,并把成JSON
{
"Attrib1":"Value1",
"Atrrib2":"Value2",
"Inners": [
{
"InnerAttrib1":"InnerValue1",
"InnerAttrib2":"InnerValue2"
},
{
"InnerAttrib1":"InnerValue2",
"InnerAttrib2":"InnerValue3"
},
{
"InnerAttrib1":"InnerValue4",
"InnerAttrib2":"InnerValue5"
}
],
"Attrib3": "anotherThing"
}
我有提取“内在”的价值观,让REST调用的函数,我的REST服务只支持一个“内部件” ATTRIB的时候,就像是对例如:
{
"Attrib1":"Value1",
"Atrrib2":"Value2",
"Inners": [
{
"InnerAttrib1":"InnerValue2",
"InnerAttrib2":"InnerValue3"
}
],
"Attrib3": "anotherThing"
}
所以......我做了从“内件”提取一个值的函数:
public List<string> fillClient(JObject request)
{
var auxiliarJson = new JObject();
var arraytoMerge=new JArray();
var listResult = new List<string>();
clientRest.EndPoint = "ClientEndPoint";
auxiliarJson = request;
arraytoMerge = request.SelectToken("Inners") as JArray;
for (int innerCount = 0; innerCount < arraytoMerge.Count; innerCount++)
{
auxiliarJson.SelectToken("Inners").Replace(arraytoMerge[innerCount]);//My problem!
clientRest.PostData = request.ToString(); //fill the data to send
listResult.Add(clientRest.MakeRequest()); //Send the request
}
return listResult;
}
当我做这个,我有一个错误(错误请求),调试我发现,我的“内件”就是如此:
"Inners": "{
"InnerAttrib1":"InnerValue1",
"InnerAttrib2":"InnerValue2"
}"
如何才能消除这种行情中括号的开始和结束,或者如果你可以向我建议一些替代方案,使其相同,谢谢!