我试图从项目文件夹中读取文件,并将其作为json返回内容。
这是我的代码:
string allText = System.IO.File.ReadAllText(jsonPath);
object jsonObject = JsonConvert.DeserializeObject(allText);
return Ok(jsonObject);
这是文件内容:
[{"grouping":"IS3","count":327.0,"population":12.0,"weight":31.0},
{"grouping":"ISO","count":31.0,"population":31.0,"weight":27.0}]
This is the response from postman:
[
[
[
[]
],
[
[]
]
]
]
If I put a break point I can see that the jsonObject is filled correctly.
I forgot to say I made the file with another endpoint reading from a file excel. The fields are not always the same, I made the object dinamicaly so I can't use a class.
I'd like to return a json as content type, not a text.
jsonObject.GetType()
是什么? - mjwills