完成阅读JSON内容后遇到的其他文字:; 。路径'',第1行,第46位。“"请帮忙... [英] Additional text encountered after finished reading JSON content: ; . Path '', line 1, position 46."" please help...

查看:96
本文介绍了完成阅读JSON内容后遇到的其他文字:; 。路径'',第1行,第46位。“"请帮忙...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Web应用程序,它检索json数据作为输出,现在我希望它显示在datatable中。当我使用newtosoft json时,它说

类型'Newtonsoft的例外.Json.JsonReaderException'发生在Newtonsoft.Json.dll中但未在用户代码中处理。

我是web api的新手。我的json即使在数组中也包含大量数据...请帮助



我尝试过:



 public void Button1_Click(object sender,EventArgs e)
{

string myDynamicJSON = jsontb.Text;


//在JsonConvert.DeserializeObject中使用动态关键字,这里需要导入Newtonsoft.Json
dynamic myObject = JsonConvert.DeserializeObject(myDynamicJSON);

//从动态对象绑定gridview
GridView1.DataSource = myObject;
GridView1.DataBind();

//将DataTable与JsonConvert.DeserializeObject一起使用,这里需要使用System.Data导入;
DataTable myObjectDT = JsonConvert.DeserializeObject< datatable>(myDynamicJSON);

//从动态对象绑定gridview
GridView1.DataSource = myObjectDT;
GridView1.DataBind();
}

解决方案

Quote:

读完JSON内容后遇到的其他文字:; 。路径'',第1行,第46位。



如果您仔细阅读了错误消息;它会告诉您在指示位置后您的json文件不是json文件。 />
只有你的代码才能保护它免受try / catch结构的这种问题。

否则,有趣的是转储json文件的开头。


你的代码没有足够的数据来提供正确的解决方案。



但在我看来你的问题是与 DeserializeObject line



 DataTable myObjectDT = JsonConvert.DeserializeObject< datatable>(myDynamicJSON); 



您反序列化的数据可能与 datatable 不一样。检查对象类型是否与 myDynamicJSON 和 datatable 。一个常见错误是人们试图将对象的集合反序列化为单个对象。请检查你的对象是否属实情况下。

I was developing a web application which retrieves json data as output and now i want it to be shown in a datatable.When i use newtosoft json its saying

""An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll but was not handled in user code.

I was new in web api. my json is containing lots of data even in arrays... please help

What I have tried:

public void Button1_Click(object sender, EventArgs e)
        {
           
            string myDynamicJSON = jsontb.Text;
            

            //Using dynamic keyword with JsonConvert.DeserializeObject, here you need to import Newtonsoft.Json  
            dynamic myObject = JsonConvert.DeserializeObject(myDynamicJSON);

            //Binding gridview from dynamic object   
            GridView1.DataSource = myObject;
            GridView1.DataBind();

            //Using DataTable with JsonConvert.DeserializeObject, here you need to import using System.Data;  
            DataTable myObjectDT = JsonConvert.DeserializeObject<datatable>(myDynamicJSON);

            //Binding gridview from dynamic object   
            GridView1.DataSource = myObjectDT;
            GridView1.DataBind();
        }

解决方案

Quote:

Additional text encountered after finished reading JSON content: ; . Path '', line 1, position 46."


If you read carefully the error message; it tells you that your json file is not a json file after the position indicated.
Only thing to do with your code is to protect it against such problem with a try/catch structure.
Otherwise, what is interesting is a dump of beginning of your json file.


your code do not have enough data to give a proper solution.

but in my opinion your problem is with the DeserializeObject line

DataTable myObjectDT = JsonConvert.DeserializeObject<datatable>(myDynamicJSON);


the data you deserializing may not be same as datatable. check if the object type matches for myDynamicJSON and datatable. One common mistake is that people try to deserialize collection of object to a single object. please check if it is true in your case.


这篇关于完成阅读JSON内容后遇到的其他文字:; 。路径'',第1行,第46位。“&quot;请帮忙...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆