Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Json不';我不能解析所有东西_C#_Json - Fatal编程技术网

C# Json不';我不能解析所有东西

C# Json不';我不能解析所有东西,c#,json,C#,Json,我的JSON响应如下: { "stepLang":"en", "isFromCache":true, "isInNotebook":false, "standardQuery":"(x-4)(x+3)\\le 0", "relatedProblems":[ ], "subject":"Algebra", "topic":"Inequalities", "subTopic":"PolynomialIneqSolver", "solutions":[ { "step_input":"(x-4

我的JSON响应如下:

    {
"stepLang":"en",
"isFromCache":true,
"isInNotebook":false,
"standardQuery":"(x-4)(x+3)\\le 0",
"relatedProblems":[
],
"subject":"Algebra",
"topic":"Inequalities",
"subTopic":"PolynomialIneqSolver",
"solutions":[
{
"step_input":"(x-4)(x+3)\\le 0",
"entire_result":"-3\\le x\\le 4",
"solvingClass":"Inequalities",
"isInterimStep":true,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"(x-4)(x+3)\\le 0{\\quad:{\\quad}\\begin{bmatrix}\\mathrm{Solution:} \u0026 -3\\le x\\le 4 \\\\ \\mathrm{Interval Notation:}\u0026 [-3,4]\\end{bmatrix}"
}
},
"steps":[
{
"step_input":"(x-4)(x+3)\\le 0",
"isInterimStep":true,
"isOpen":false,
"isShowSolutionAfterStep":false,
"isLocked":true,
"title":{
"text":{
"createdText":"\\mathrm{Find the signs of the factors of }(x-4)(x+3)"
}
},
"steps":[
{
"isInterimStep":true,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"\\mathrm{Find the signs of }x-4"
}
},
"steps":[
{
"step_input":"x-4\u003d0",
"entire_result":"x\u003d4",
"solvingClass":"Equations",
"isInterimStep":true,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"x-4\u003d0:{\\quad}x\u003d4"
}
},
"steps":[
{
"entire_result":"x-4+4\u003d0+4",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"explanation":[
{
"createdText":"\\mathrm{Add }4\\mathrm{ to both sides}"
}
]
},
{
"entire_result":"x\u003d4",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"\\mathrm{Simplify}"
}
}
}
]
},
{
"step_input":"x-4\u003c0",
"entire_result":"x\u003c4",
"solvingClass":"Inequalities",
"isInterimStep":true,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"x-4\u003c0:{\\quad}x\u003c4"
}
},
"steps":[
{
"entire_result":"x-4+4\u003c0+4",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"explanation":[
{
"createdText":"\\mathrm{Add }4\\mathrm{ to both sides}"
}
]
},
{
"entire_result":"x\u003c4",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"\\mathrm{Simplify}"
}
}
}
]
},
{
"step_input":"x-4\u003e0",
"entire_result":"x\u003e4",
"solvingClass":"Inequalities",
"isInterimStep":true,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"x-4\u003e0:{\\quad}x\u003e4"
}
},
"steps":[
{
"entire_result":"x-4+4\u003e0+4",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"explanation":[
{
"createdText":"\\mathrm{Add }4\\mathrm{ to both sides}"
}
]
},
{
"entire_result":"x\u003e4",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"\\mathrm{Simplify}"
}
}
}
]
}
]
},
{
"isInterimStep":true,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"\\mathrm{Find the signs of }x+3"
}
},
"steps":[
{
"step_input":"x+3\u003d0",
"entire_result":"x\u003d-3",
"solvingClass":"Equations",
"isInterimStep":true,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"x+3\u003d0:{\\quad}x\u003d-3"
}
},
"steps":[
{
"entire_result":"x+3-3\u003d0-3",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"explanation":[
{
"createdText":"\\mathrm{Subtract }3\\mathrm{ from both sides}"
}
]
},
{
"entire_result":"x\u003d-3",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"\\mathrm{Simplify}"
}
}
}
]
},
{
"step_input":"x+3\u003c0",
"entire_result":"x\u003c-3",
"solvingClass":"Inequalities",
"isInterimStep":true,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"x+3\u003c0:{\\quad}x\u003c-3"
}
},
"steps":[
{
"entire_result":"x+3-3\u003c0-3",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"explanation":[
{
"createdText":"\\mathrm{Subtract }3\\mathrm{ from both sides}"
}
]
},
{
"entire_result":"x\u003c-3",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"\\mathrm{Simplify}"
}
}
}
]
},
{
"step_input":"x+3\u003e0",
"entire_result":"x\u003e-3",
"solvingClass":"Inequalities",
"isInterimStep":true,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"x+3\u003e0:{\\quad}x\u003e-3"
}
},
"steps":[
{
"entire_result":"x+3-3\u003e0-3",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"explanation":[
{
"createdText":"\\mathrm{Subtract }3\\mathrm{ from both sides}"
}
]
},
{
"entire_result":"x\u003e-3",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"\\mathrm{Simplify}"
}
}
}
]
}
]
}
]
},
{
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"\\mathrm{Summarize in a table:}"
}
},
"explanation":[
{
"createdText":"\\begin{table} \u0026x\u003c-3\u0026x\u003d-3\u0026-3\u003cx\u003c4\u0026x\u003d4\u0026x\u003e4\u0026\\\\x-4\u0026-\u0026-\u0026-\u00260\u0026+\u0026\\\\x+3\u0026-\u00260\u0026+\u0026+\u0026+\u0026\\\\(x-4)(x+3)\u0026+\u00260\u0026-\u00260\u0026+\u0026\\\\\\summaryline\\end{table}"
}
]
},
{
"entire_result":"x\u003d-3\\lor -3\u003cx\u003c4\\lor x\u003d4",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":true,
"title":{
"text":{
"createdText":"\\mathrm{Identify the intervals that satisfy the required condition:} \\le 0"
}
}
},
{
"entire_result":"-3\\le x\\le 4",
"isInterimStep":true,
"isOpen":false,
"isShowSolutionAfterStep":true,
"isLocked":true,
"title":{
"text":{
"createdText":"\\mathrm{Merge Overlapping Intervals}"
}
},
"steps":[
{
"image":"/images/interval?expression\u003d%28y_%7B0%7D%3D-3%29%5Clor+%28-3%3Cy_%7B0%7D%3C4%29",
"entire_result":"-3\\le x\u003c4",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"\\mathrm{The union of two intervals is the set of numbers which are in either interval}\u003cbr/\u003ex\u003d-3\\quad\\mathrm{or}\\quad -3\u003cx\u003c4"
}
}
},
{
"image":"/images/interval?expression\u003d%28-3%5Cle+y_%7B0%7D%3C4%29%5Clor+%28y_%7B0%7D%3D4%29",
"entire_result":"-3\\le x\\le 4",
"isInterimStep":false,
"isOpen":false,
"isShowSolutionAfterStep":false,
"title":{
"text":{
"createdText":"\\mathrm{The union of two intervals is the set of numbers which are in either interval}\u003cbr/\u003e-3\\le x\u003c4\\quad\\mathrm{or}\\quad x\u003d4"
}
}
}
]
}
],
"practiceLink":"/practice/inequalities-practice#area\u003dmain\u0026subtopic\u003dQuadratic",
"practiceTopic":"Polynomial Inequalities"
}
],
"plotInfo":{
"variable":"x",
"funcsToDraw":{
"funcs":[
{
"evalFormula":"x\u003d-3",
"displayFormula":"x\u003d-3",
"attributes":{
"color":"BLACK",
"lineType":"NORMAL",
"labels":[
],
"isAsymptote":false
}
},
{
"evalFormula":"x\u003d4",
"displayFormula":"x\u003d4",
"attributes":{
"color":"BLACK",
"lineType":"NORMAL",
"labels":[
],
"isAsymptote":false
}
}
],
"attributeFactory":{
"color":"PURPLE",
"lineType":"NORMAL",
"labels":[
],
"isAsymptote":false
}
},
"linesToDraw":[
],
"fills":[
{
"ranges":[
{
"fst":"-3.0",
"snd":"4.0"
}
],
"funcIndices":[
],
"funcs":[
],
"xIneq":true,
"yIneq":false,
"twoVar":false,
"trueAboveLine":false,
"color":"rgba(171, 181, 235, 0.3)"
}
],
"functionChanges":[
{
"origFormulaLatex":[
],
"finalFormulaLatex":[
],
"plotTitle":"-3\\le x\\le 4",
"paramsLatex":[
],
"paramsReplacementsLatex":[
]
}
],
"localBoundingBox":{
"xMin":-5.0,
"xMax":6.0,
"yMin":-2.0,
"yMax":8.0
},
"graphCalcInputErrors":[
],
"intervals":[
{
"mind":-3.0,
"maxd":4.0,
"minInclusive":true,
"maxInclusive":true,
"maxFinite":true,
"minFinite":true,
"isAllR":false,
"isPoint":false
}
],
"isInCache":false,
"imageAPI":"-3\\le x\\le 4"
},
"numberLineInfo":{
"imageAPI":"/images/numberLine?xmin\u003d-5.0\u0026xmax\u003d6.0\u0026expression\u003d-3%5Cle+y_%7B0%7D%5Cle+4"
},
"dym":{
"inputEquation":"\\left(x-4\\right)\\left(x+3\\right)\\le 0",
"originalEquation":"(x-4)(x+3)\\le 0",
"outEquation":"(x-4)(x+3)\\le 0",
"dymEquation":"(x-4)(x+3)\\le 0",
"isTemplate":false,
"showDidYouMean":false,
"showInstead":false
}
我尝试使用Newtonsoft.Json和代码解析它

string NotParsedResponse = await response.Content.ReadAsStringAsync(); // json above
dynamic dynObj = JsonConvert.DeserializeObject(NotParsedResponse);
foreach (dynamic step in dynObj.solutions)
{
    foreach (dynamic step1 in step.steps)
    {
        Result += @" \\\ " + step1.title + @" \\\ " + step1.entire_result + @" \\\ " + step1.step_input ;
    }
}
我想得到标题、步骤输入、整个结果之后的所有内容,但返回的结果不正确。 因此,我决定更改代码,如:

foreach (dynamic step in dynObj.solutions.steps)
{
  Result += step.step_input;
}
我有个例外
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“Newtonsoft.Json.Linq.JArray”不包含基于您提供的Json的“步骤”定义。应该更像

foreach (dynamic step in dynObj.solutions)
{
   Result += step.step_input;
}

solutions
是根据您指定的JSON的数组

您还可以用这个JSON创建绑定对象吗?数据似乎不是非结构化的,而且更易于使用

var dynObj=JsonConvert.DeserializeObject(NotParsedResponse);
公共类根
{
公共列表解决方案{get;set;}
公共类步骤
{
公共字符串步骤_输入{get;set;}
//其余物业
}
}
--编辑
solutions
数组中的第一个对象包含非常嵌套的结构:

{
 "steps: [
  ...
  {
   ...
   "steps": [
    ...
    {
     ...
     "steps" : [
     ]
    }
   ]
  }
 ]
}
如果是这种情况,您必须将结构更改为:

public class Root
{
  public List<Step> solutions { get;set; }

  public class Step 
  {
    public string step_input { get; set; }
    // rest of properties
    public List<Step> steps { get; set; }
  }
}

首先,上面的JSON缺少结束括号,但这可能是在文章中复制和粘贴的问题


其次,如果从传入的JSON来看,第一个代码片段在形式上是正确的:您有一个
解决方案,它是一个数组,您必须对它进行迭代或获取其中的唯一项。

也许您可以使用递归来存储所有输入和结果


foreach(dynObj.解决方案中的var步骤)
{
if(step.steps!=null)
{
打印(步骤.步骤);
}
}
公共作废打印(IEnumbered steps)
{
foreach(var步进)
{
var title=$“title:{step?.title?.text?.createdText??string.Empty}”;
var txt=$“输入:{step.step_输入??string.Empty}”;
var res=$“结果:{step.整_结果??string.Empty}”;
//添加到数组
if(step.steps!=null&&step.steps.Any()){
打印(步骤.步骤);
}
}
}

解决方案
中没有名为
步骤
的条目。你打错了吗?你的目标是什么?不清楚您想要实现什么。我试图获取步骤输入,标题字段no,我想在解决方案中循环步骤确定将json放入json格式化程序后,事情变得更清楚了。。。您需要递归地循环步骤内的元素。@log0…但不能使用动态,尽管:架构不清楚,第一次尝试访问“步骤”时,将抛出一个异常。我想循环所有步骤支持的answer.foreach(步骤.steps中的var step1){Result+=step1.step_input;}类似于这样的内容是的,但它不会循环所有步骤您的意思是要迭代所有嵌套的步骤?有很多“步骤”!是的,我想循环所有步骤……那么,我想使用动态对象会很困难。为什么不使用JLinq遍历JSON?这会更简单……有没有关于如何获取标题字段的建议?是的,这很有效,但我使用了嵌套foreach感谢您的回答还有步骤中的“标题”字段如何才能获得itI更新的解决方案与标题属性的价值,我希望这将有所帮助。
foreach(var step in dynObj.solutions) {
 if(step.steps != null) {
  ... another loop
 }
}