博文

目前显示的是标签为“JSON”的博文

Jackson in Java for JSON

Jackson, https://github.com/FasterXML/jackson Jackson has been known as "the Java JSON library" or "the best JSON parser for Java". Or simply as "JSON for Java". Jackson 3 core libs:streaming,databind,annotations. Jackson version: 1.x: org.codehaus.jackson.xxx;  2.x: com. fastxml .jackson.xxx To capitalize the first letter, you need the following: 1. Maven adds: <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.5.3</version> </dependency> 2. Add to the attributes: @JsonProperty( "Code") 3. Add to the Getter method: @JsonIgnore To implement toString()  import com.alibaba.fastjson.annotation. JSONField ; import com.fasterxml.jackson.annotation. JsonIgnore ; import com.fasterxml.jackson.annotation. JsonProperty ; import net.sf.json.JSONObject ; @Override public String toString () { return JSONObje...

JSON & C#

1. System.Text.Json.Utf8JsonReader ref: https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0  https://github.com/ysharplanguage/FastJsonParser#Overview 2. Newtonsoft.Json library  using NewTonsoft.Json; //Using Manage NuGet Packages installs Newtonsoft.Json .  Cat cat2 = new Cat(){name="hik",age=3};  string s1= Newtonsoft.Json.JsonConvert . SerializeObject (cat2);   Cat   cat3 = JsonConvert . DeserializeObject <Cat>(JSONstr);   string outStr2 = JsonConvert.SerializeObject(cat2); private string CapitalFirstLetter(string s)  {             try             {                 string rs = char.ToUpper(s[0]) + s.Substring(1);                 return r...

jQuery and Form

inside posting page function postToError ( CBaseError ) { var e = encodeURI ( JSON . stringify ( CBaseError . errors ). replace ( /"/ g , '&quot;' )); //way 1 $('<form action="./ErrorP" method="post"><input name="error" type="hidden" value="'+e+'"></form>').appendTo('body').submit(); //way 2 var newForm = $ ( '<form>' , { 'action' : './ ErrorP ' , 'method' : 'post' }). append ( $ ( '<input>' , { 'name' : 'error' , 'value' : e , 'type' : 'hidden' })); newForm . appendTo ( 'body' ); newForm . submit (); } inside page posted to < script > var Error ={ "errors" :[]}; var e = '@ViewData["Error"]' ; e = e . replace ( /&quot;/ g , '"' ); var a = decodeU...

Return JSON from a JSP

图片
I need using a JSP returns JSON, so wrote the following codes for testing. Fortunately i t works. /*  This file name is json.jsp. It posts itself, then get JSON. */ <%response.setHeader("Cache-Control", "no-cache");%> <%response.setHeader("Pragma", "no-cache");%> <% String t = request.getParameter("t"); if(t==null){ %> <!DOCTYPE html> <% response.setHeader("contentType","text/html;charset=UTF-8"); %> <script type="text/javascript">   var XHR;   function requestJSON(){       if ( window.XMLHttpRequest )          XHR = new XMLHttpRequest();       else if ( window.ActiveXObject ) {          try {             XHR = new ActiveXObject('Msxml2.XMLHTTP');          }      ...

Send JSONP Cross-domain Requests

From:w w w . j son.com/100-awesome-uses/87-send-jsonp-cross-domain-requests 12.16.2013   Dave Romero   Cross-domain Requests In developing web applications it's commonplace to send and receive data to APIs (Application Programmable Interfaces) that exist on other domains. This cross-domain communication is often performed directly in the browser, on the client-side using JavaScript. Cross-domain communication can be accomplished using a server-side languages like Python, Nodejs, PHP, etc., however for cases where responses from cross-domain requests are utilized in the browser, JavaScript can save time and simplify development. Addintionaly, JavaScript requests are asynchronous— meaning they can be run in parallel with other processes. For example, JavaScript requests to other domains can be processed asynchronously while the page is still loading. Same-origin Policy Same-origin policy is an important security concept in client-side programming languages ...

json and java

Take  a look FastJSON that is  JSON Processor. h t t p : / / c o d e . alibabatech.com/w i k i/display/FastJSON/Overview h t t p s : / / github .com/AlibabaTech/fastjson/ h t t p s : / / github .com/alibaba/fastjson

Escape for XML & JSON

/**  * @author Jin  * @version 1.0.0  */ public class XmlTool {     public final static String JSONPARSE="forJSONparse";     public XmlTool() {         super();     }     /**      * Replace the five special characters by five "predefined entities".      * The XML specification defines five "predefined entities" representing special characters,      * and requires that tool honor them.The entities can be explicitly declared in a DTD.      * The table below lists the five XML predefined entities. The "Name" column mentions the entity's name. The "Character" column shows the character.      * <p>      * Name     Character      * quot     "      * amp     &   ...

String to JSON Object using backslash escapes (Encode and Decode)

http://json.org A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes . A character is represented as a single character string. A string is very much like a C or Java string. In ECMA262 version 5 Javascript Object to JSON JSON to Javascript Object JSON.stringify() JSON.parse()  <script type="text/javascript">   var j='{"acct_id":100001,"acct_name":"na \\" me","email":"Jet \' mail"}';   var o=JSON.parse(j);   alert(o.acct_id+o.acct_name+o.email);   var jj='[{"acct_id":100000,"acct_name":"name0","email":"Jemail0"}]';    var oo=[];    oo=JSON.parse(jj);   alert(oo[0].acct_id+oo[0].acct_name+oo[0].email); //------         function getJsonObjLength(jsonObj){             var l=0;for(var i in jsonObj){l++;}return l;         }  ...

JSON processors

1. Jackson is a High-performance JSON processor. References: http://jackson.codehaus.org/ http://wiki.fasterxml.com/JacksonHome How to convert Java object to / from JSON http://www.mkyong.com/java/how-to-convert-java-object-to-from-json-jackson/ http://www.cowtowncoder.com/blog/archives/2008/12/entry_121.html 2.Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of. References: http://code.google.com/p/google-gson/ 3.JSON-lib is a java library for transforming beans, maps, collections, java arrays and XML to JSON and back again to beans and DynaBeans. It is based on the work by Douglas Crockford in http://www.json.org/java References: http://json-lib.sourceforge.net/