【如何使用JSON.NET在C#中序列化PSObject?】教程文章相关的互联网学习教程文章

c# – 使用Json.NET将JObject的一部分转换为Dictionary【代码】

我正在测试Json.Net以准备一个不同的项目,我遇到了一些麻烦.我想要做的是将moretests的内容转换为Dictionary.这是我的完整代码:class Program {static void Main(string[] args){string json = @"{'test': 'a','test2': 'b','moretests':{'test3': 'c','test4': 'd'}}";JObject parsed = JObject.Parse(json);IDictionary<string, JToken> results = (JObject)parsed["moretests"];Dictionary<string, string> results2 = results...

Java-Class-I:com.alibaba.fastjson.JSONObject【代码】

ylbtech-Java-Class-I:com.alibaba.fastjson.JSONObject 1.返回顶部 1.1、import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONObject;1.2、String objJSON = "{key:value}";JSONObject responseObj = JSON.parseObject(objJSON);String key = responseObj.getString("key");2、2.返回顶部?3.返回顶部?4.返回顶部1、/** Copyright 1999-2017 Alibaba Group.** Licensed under the Apache License, Version 2.0 (th...

java – 如何将JSONObject从Android应用程序传递到PHP文件?【代码】

我想向PHP服务器发送一个简单的JSON对象,但是当我尝试在服务器端检索该对象时,我的意思是我的$_POST变量是空的.服务器端是PHP 5.2,我使用的是android模拟器10 …有人可以查看我的代码并告诉我出了什么问题吗?非常感谢public void uploadJSon() throws ClientProtocolException, IOException, JSONException{HttpClient httpclient = new DefaultHttpClient();String url = "http://so-dev-deb.niv2.com/suivi_activite/test.php";...

c# – 无法隐式转换类型’Newtonsoft.Json.Linq.JObject’【代码】

那是其中的一天;我设法解决了2个问题,但我不确定如何修复第3个错误. 我需要返回一个json对象,但是我收到以下错误:Error 1 Cannot implicitly convert type 'Newtonsoft.Json.Linq.JObject' to 'System.Collections.Generic.IEnumerable<Newtonsoft.Json.Linq.JObject>'. An explicit conversion exists (are you missing a cast?)任何人都可以帮我解决这个错误吗?public static IEnumerable<JObject> GetListOfHotels() {con...

c# – 无法将将DynamicObject扩展为JSON字符串的类序列化.【代码】

我有类foo,它扩展了DynamicObject类.该类还包含Dictionary类型的属性. 当我尝试使用Newton.Soft Json转换器序列化它时.我得到“{}”作为空白对象. 以下是我的代码:public class Foo: DynamicObject{/// <summary>/// Gets or sets the properties./// </summary>/// <value>The properties.</value>public Dictionary<string, object> Properties { get; set; } = new Dictionary<string, object>();/// <summary>/// Get...

PHP,json_encode,SimpleXML Object的json_decode【代码】

我的应用程序中的函数执行以下操作: >使用Snoopy捕获网页>将结果加载到DOMDocument中>将DOMDocument加载到简单XML对象中>运行XPath以隔离所需的文档部分> json_encode结果并保存到数据库供以后使用. 从数据库中恢复此块并对其进行解码时出现问题.我在var_dump对象时可以看到@attributes,但找不到允许我访问它们的命令组合. 错误消息是:致命错误:无法使用stdClass类型的对象作为数组 下面是我的对象示例.我曾尝试过,其中包括以前...

使用Volley with JsonObjectRequest时无法从PHP获取参数【代码】

我正在使用Volley框架和JsonObjectRequest请求.我在用JsonObjectRequest loginRequest = new JsonObjectRequest(b.toString(), params,new Listener<JSONObject>() {},new Response.ErrorListener() {});params变量包含参数,它是一个JSONObject. 问题是我无法在PHP代码中访问任何这些变量. $_POST或$_REQUEST变量什么都没给我. 我也尝试过类似下面的东西,但没有运气.$data = json_decode(file_get_contents("php://input"));解决方...

c# – Json.Net根据值选择Object【代码】

我有一个看起来像这样的Json对象:{wvw_matches: [{wvw_match_id: "1-4",red_world_id: 1011,blue_world_id: 1003,green_world_id: 1002,start_time: "2013-09-14T01:00:00Z",end_time: "2013-09-21T01:00:00Z"},{wvw_match_id: "1-2",red_world_id: 1017,blue_world_id: 1021,green_world_id: 1009,start_time: "2013-09-14T01:00:00Z",end_time: "2013-09-21T01:00:00Z"}] }它包含的数组中的对象比上面显示的示例多得多.无论如何...

杰克逊:从Json更新(不创建新对象)JavaObject?【代码】

好的,我有一个json说userjson = { fname : "ABC", lname : "DEF" }和用户Pojo对象User {String id, String email,String fname,String lname }现在使用我的Jackson,我知道如何从userjson创建User实例,但是如何从userjson更新现有的User实例,因为我的用户实例已经有一些其他模块已设置的属性. 现在我正在做的是将userjson转换为userHasMap,然后手动设置所有值userInstance.setFName(userHasMap.get('fname')) userInstance.setLName...

java – ObjectMapper追加文件JSON【代码】

试图了解一些杰克逊,所以我正在编写一个简单的程序来读取文件/创建一个文件来存储一些JSON.在Jackson网站上,我想出了如何从文件中读取和写入,但在我的基本程序中,我也想附加.我基本上试图存储一个购物清单列表.有一个购物清单对象,其中包含商店名称,该商店的amd商品. 麻烦的是我无法找到将另一个条目追加到文件末尾的方法(采用JSON格式).这是我到目前为止所使用的,您可以忽略它的第一位,它只是一个愚蠢的控制台扫描仪要求输入:pub...

java – JsonObject和JSONObject之间有什么不同

JsonObject和JSONObject之间有什么不同? 我有点混淆JsonObject和JSONObject,当我们使用put,add和addproperty方法时. 提前致谢.解决方法:Android SDK提供JSONObject.这可以通过导入org.json.JSONObject来使用. JSONObject的文档是here. 任何其他变体将来自库或链接项目. cricket_007给出的例子是来自Gson库的JsonObject.这可以通过导入com.google.gson.JsonObject来使用. JsonObject的文档是here. 请注意JSONObject和JsonObject的i...

java – 如何从路径中获取JSONObject中的嵌套值?【代码】

我正在尝试实现一个给定任何JSONObject和路径String的函数,它将返回对应于该路径的对象的属性. 例如,给这个json:{ "name": "John", "friends": [{"name": "Paul","age":42},{"name": "Peter","age":24}], "address": {"city": "London"} }> getAttribute(jsonObject,“name”)应该返回“John”> getAttribute(jsonObject,“address.city”)应该返回“伦敦”> getAttribute(jsonObject,“friends [0] .name”)应返回“Paul” 请注...

c# – System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObject在序列化时忽略NonSerialized属性【代码】

如果我尝试使用System.Runtime.Serialization.Json.DataContractJsonSerializer序列化以下ClassToSerialize类的对象[DataContract,Serializable] public class ClassToSerialize {[NonSerialized] private bool _mf;public bool IsMf{ get { return _mf};set{ _mf = value;} }[DataMember]public char PrimaryExc { get; set; } }public class TestClass {ClassToSerialize obj = new ClassToSerialize{PrimaryExchange = ...

fastJson中java对象 jsonObject jsonArray之间转换【图】

fastJson中java对象 jsonObject jsonArray之间转换 一、介绍 简介:JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式 二、使用 1、java对象转jsonObjectUser u = new User(); u.setName("yinyuy"); JSONObject json = (JSONObject) JSONObject.toJSON(u); 2、jsonArray添加jsonObjectUser u = new User(); u.setName("yinyuy"); JSONArray jsonArray = new JSONArray(); JSONObject json = (JSONObject) JSONObject.t...

c# – 在JSON.Net 4.0中使用JObject和JProperty【代码】

我试图以这种格式反序列化JSON:{"data": [{"installed": 1,"user_likes": 1,"user_education_history": 1,"friends_education_history": 1,"bookmarked": 1}] }到这样一个简单的字符串数组:{"installed","user_likes","user_education_history","friends_education_history","bookmarked" }使用JSON.NET 4.0 我已经使用`CustomCreationConverter’工作了public class ListConverter : CustomCreationConverter<List<string>> { p...