net.sf.jsonObject().toString()如何保留value小数点后的零值

举个栗子,json.put("a",new BigDecimal("1.00")).toString()让他输入为{"a","1.00"},而不是{"a","1"}

1个回答

可以参考下这段代码,JSONObject.toString()方法并没有调用里面对象的toString()方法.

public class Test1 {
public static void main(String[] args) {
JSONObject json = new JSONObject();
json.put("a", new BigDecimal("0.100"));
json.put("b", new Person());

    json.put("c", new BigDecimal("0.100").toString());
    json.put("d", new Person().toString());

    System.out.println(json.toString());
}

}

class Person implements Serializable {
private static final long serialVersionUID = -2895332854798849799L;
private int s = 0;
public boolean b = true;

@Override
public String toString() {
    return "Person [s=" + s + ", b=" + b + "]";
}

}

m0_37710091
m0_37710091 解决了,谢谢
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
java 用import net.sf.json.JSONArray; import net.sf.json.JSONObject;这个工具转换的jsonArray?

JosnArray arr = new JsonArray(); arr.add("1"); arr.add("2"); arr.add{"3"} 我想把这个数组输出 变成["3","2","1"]而不是["1","2","3"]求大神指点

net.sf.json.JSONException:

严重: Servlet.service() for servlet [UserServlet] in context with path [/smbms] threw exception net.sf.json.JSONException: java.lang.reflect.InvocationTargetException at net.sf.json.JSONObject._fromBean(JSONObject.java:959) at net.sf.json.JSONObject.fromObject(JSONObject.java:194) at net.sf.json.JSONObject._processValue(JSONObject.java:2793) at net.sf.json.JSONObject._setInternal(JSONObject.java:2817) at net.sf.json.JSONObject.setValue(JSONObject.java:1527) at net.sf.json.JSONObject._fromBean(JSONObject.java:946) at net.sf.json.JSONObject.fromObject(JSONObject.java:194) at net.sf.json.JSONArray._processValue(JSONArray.java:2562) at net.sf.json.JSONArray.processValue(JSONArray.java:2593) at net.sf.json.JSONArray.addValue(JSONArray.java:2580) at net.sf.json.JSONArray._fromCollection(JSONArray.java:1084) at net.sf.json.JSONArray.fromObject(JSONArray.java:147) at net.sf.json.JSONArray.fromObject(JSONArray.java:129) at cn.smbms.servlet.UserServlet.getUserList(UserServlet.java:108) at cn.smbms.servlet.UserServlet.service(UserServlet.java:37) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1773) at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1132) at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:686) at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715) at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:290) at net.sf.json.JSONObject._fromBean(JSONObject.java:931) ... 33 more Caused by: java.lang.IllegalArgumentException at java.sql.Date.getHours(Date.java:177) ... 43 more

json转换出现警告怎么去除

下面是访问后台时json转换时出现的警告, 在网上搜索下, 很多人出现过这种情况, 没搜索到解决方案, 希望大家帮忙可以去除掉这些警告, 虽然不影响使用 [code="java"]2011-8-19 10:20:11 net.sf.json.JSONObject defaultBeanProcessing 信息: Property 'parent' of class com.huawei.ifree.autotest.log.analyse.platform.checkednode.CheckedTestSuiteLogNode has no read method. SKIPPED 2011-8-19 10:20:11 net.sf.json.JSONObject defaultBeanProcessing 信息: Property 'parent' of class com.huawei.ifree.autotest.log.analyse.platform.checkednode.CheckedTestSuiteLogNode has no read method. SKIPPED 2011-8-19 10:20:11 net.sf.json.JSONObject defaultBeanProcessing 信息: Property 'parent' of class com.huawei.ifree.autotest.log.analyse.platform.node.ProjectLogNode has no read method. SKIPPED[/code]

net.sf.json.JSONException

net.sf.json.JSONException: A JSONObject text must begin with '{' at character 4 of dachie({"result":[]}) 求各位大佬指教这是什么错啊 具体是由什么引起的![图片说明](https://img-ask.csdn.net/upload/201704/15/1492249536_805706.png)![图片说明](https://img-ask.csdn.net/upload/201704/15/1492250267_582476.png)

内存溢出错误-Java heap space

环境是纯JAVA 用Eclipse开发 功能是通过API获取微博信息 之前在网上找到相关错误资料说是修改JVM的HEAP大小 但我修改后还是报错。希望大家提供解决方案或者思路 谢谢 **报错信息:** Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at org.apache.commons.collections.map.ListOrderedMap.<init>(ListOrder ap.java:100) at net.sf.json.JSONObject.<init>(JSONObject.java:1450) at net.sf.json.JSONObject._fromJSONObject(JSONObject.java:919) at net.sf.json.JSONObject.fromObject(JSONObject.java:155) at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:108) at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:238) at net.sf.json.JSONArray._processValue(JSONArray.java:2513) at net.sf.json.JSONArray.processValue(JSONArray.java:2538) at net.sf.json.JSONArray.addValue(JSONArray.java:2525) at net.sf.json.JSONArray._fromJSONArray(JSONArray.java:1096) at net.sf.json.JSONArray.fromObject(JSONArray.java:121) at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:105) at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:238) at net.sf.json.JSONObject._processValue(JSONObject.java:2655) at net.sf.json.JSONObject.processValue(JSONObject.java:2721) at net.sf.json.JSONObject.setInternal(JSONObject.java:2736) at net.sf.json.JSONObject._fromJSONObject(JSONObject.java:944) at net.sf.json.JSONObject.fromObject(JSONObject.java:155) at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:108) at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:238) at net.sf.json.JSONObject._processValue(JSONObject.java:2655) at net.sf.json.JSONObject.processValue(JSONObject.java:2721) at net.sf.json.JSONObject.setInternal(JSONObject.java:2736) at net.sf.json.JSONObject._fromJSONObject(JSONObject.java:944) at net.sf.json.JSONObject.fromObject(JSONObject.java:155) at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:108) at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:238) at net.sf.json.JSONArray._processValue(JSONArray.java:2513) at net.sf.json.JSONArray.processValue(JSONArray.java:2538) at net.sf.json.JSONArray.addValue(JSONArray.java:2525) at net.sf.json.JSONArray._fromJSONArray(JSONArray.java:1096) at net.sf.json.JSONArray.fromObject(JSONArray.java:121)

IDEA 用不了net.sf.Json解析

![图片说明](https://img-ask.csdn.net/upload/201512/10/1449744587_181977.png) 我用idea工具开发,遇到了不能解析json这个问题有大神能解决吗? ![图片说明](https://img-ask.csdn.net/upload/201512/10/1449744638_51910.png) 该导的包全导了。 ![图片说明](https://img-ask.csdn.net/upload/201512/10/1449744707_862770.png)

报错:net.sf.json.JSONException

显示报错: ![图片说明](https://img-ask.csdn.net/upload/201705/02/1493697329_940817.png) 源代码: <% /*获取所有业务 */ String url="#url"; String param="#URL"; //地区编号 String html=""; //String temp=""; try{ String result=sendGet(url,param); result=URLDecoder.decode(result); //解析json数据 JSONObject jsonObject=JSONObject.fromObject(result); String info=jsonObject.getString("info"); JSONArray infoArray=JSONArray.fromObject(info); //拼接下面html数据 for(int i=0;i<infoArray.size();i++){ JSONObject oneObject=infoArray.getJSONObject(i); //temp=oneObject.getString("ACCEPT_USER_NAME"); //没有完成的业务就没有完成时间,需要先判断,否则报错: String finish_time=""; if(oneObject.containsKey("FINISH_TIME")){ finish_time="<script type='text/javascript'>showTime('"+oneObject.getString("FINISH_TIME")+"');</script>"; }else{ finish_time="处理中"; } String time_limit=""; if(oneObject.containsKey("TIME_LIMIT")){ time_limit="<script type='text/javascript'>showTime('"+oneObject.getString("TIME_LIMIT")+"');</script>"; }else{ time_limit="-"; } html+="<li><span class='span1'>"+oneObject.getString("RECEIVE_NUMBER")+"</span><span class='span2'><a title='"+oneObject.getString("APPLY_SUBJECT")+"'>"+oneObject.getString("APPLY_SUBJECT")+"</a></span><span class='span4'><a title='"+oneObject.getString("ORG_NAME")+"'>"+oneObject.getString("ORG_NAME")+"</a></span><span class='span4'>"+time_limit+"</span><span class='span4'>"+finish_time+"</span><span class='span3 yellow'>"+oneObject.getString("CURRENT_NODE_NAME")+"</span></li>"; } //out.print(html); }catch(Exception e){ out.print(e.toString()); } %> 麻烦高手看看是啥情况!

JSON错误:java.lang.String无法转换为JSONObject

<div class="post-text" itemprop="text"> <p>I'm developing an android app and I'm trying to use <strong><em>Volley Library</em></strong>. The problem that I can't solve is about the JSON. I checked my php file, the result and the Java code but I'm still getting the same error. </p> <p>The interesting part is that <strong><em>VolleyLog</em></strong> doesn't show an error message but, <strong><em>Log</em></strong>, does. </p> <pre><code>E/Volley﹕ [1] 2.onErrorResponse: VOLLEY_ERROR </code></pre> <p>and </p> <pre><code>E/LOG﹕ Error: org.json.JSONException: Value You of type java.lang.String cannot be converted to JSONObject </code></pre> <p>That's my PHP code:</p> <pre><code>&lt;?php # Inform which carachters type will be used. header('Content-Type: text/html; charset=utf-8'); // array for JSON response $response = array(); // include db connect class require_once ('../conn.php'); require_once('pClass.php'); error_reporting( E_ALL ); // connecting to db $db = new DB_CONNECT(); //Setting to UTF8 mysql_query("SET NAMES 'utf8_general_ci'"); mysql_query('SET character_set_connection=utf8_general_ci'); mysql_query('SET character_set_client=utf8_general_ci'); mysql_query('SET character_set_results=utf8_general_ci'); mysql_query('SET CHARACTER SET utf8'); $ff_error = "ERROR"; $arrPOI["arrPOI"] = array(); $poi=new POI(); if (isset($_REQUEST["ff_01"])) { //Execute the query $ff_01 = $_REQUEST['ff_01']; $return = mysql_query($ff_01) or die(mysql_error()); // check for empty result if (mysql_num_rows($return) &gt; 0) { while ($row = mysql_fetch_array($return)) { $poi-&gt;setPOIId($row["intPointId"]); $poi-&gt;setPOIName($row["vchPointName"]); $poi-&gt;setPOIImage($row["vchAwesomeFont"]); $poi-&gt;setStatusId($row["intStatusId"]); $poi-&gt;setLanguageId($row["intLanguageId"]); // push single category into final response array array_push($arrPOI["arrPOI"], $poi-&gt;getPOIData()); } // echoing JSON response header('Content-Type: application/json'); echo json_encode($arrPOI, JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK | JSON_NUMERIC_CHECK); } else { //No data found array_push($arrPOI["arrPOI"], $poi-&gt;getPOIData()); // echo no users JSON header('Content-Type: application/json'); echo json_encode($arrPOI); } } else { //ERROR array_push($arrPOI["arrPOI"], $poi-&gt;getPOIData()); //Echo header('Content-Type: application/json'); echo json_encode($arrPOI); } ?&gt; </code></pre> <p>The PHP result:</p> <pre><code>{"arrPOI":[{"intPOIId":1,"strPOIName":"Cinema","strPOIImage":"fa-film","intStatusId":1,"intLanguageId":1},{"intPOIId":2,"strPOIName":"Teatro","strPOIImage":"fa-smile-o|fa-frown-o","intStatusId":1,"intLanguageId":1},{"intPOIId":3,"strPOIName":"Restaurante","strPOIImage":"fa-cutlery","intStatusId":1,"intLanguageId":1},{"intPOIId":4,"strPOIName":"Bar","strPOIImage":"fa-beer","intStatusId":1,"intLanguageId":1},{"intPOIId":5,"strPOIName":"Pontos Turísticos","strPOIImage":"fa-map-marker","intStatusId":1,"intLanguageId":1},{"intPOIId":6,"strPOIName":"Cafeteria","strPOIImage":"fa-coffee","intStatusId":1,"intLanguageId":1},{"intPOIId":7,"strPOIName":"Shopping","strPOIImage":"fa-diamond","intStatusId":1,"intLanguageId":1},{"intPOIId":8,"strPOIName":"Livraria","strPOIImage":"fa-book","intStatusId":1,"intLanguageId":1},{"intPOIId":9,"strPOIName":"Show","strPOIImage":"fa-microphone","intStatusId":1,"intLanguageId":1},{"intPOIId":10,"strPOIName":"Boates","strPOIImage":"fa-glass","intStatusId":1,"intLanguageId":1},{"intPOIId":11,"strPOIName":"Lanchonete","strPOIImage":"fa-cutlery","intStatusId":1,"intLanguageId":1},{"intPOIId":12,"strPOIName":"Hotéis","strPOIImage":"fa-building","intStatusId":1,"intLanguageId":1},{"intPOIId":13,"strPOIName":"Pub","strPOIImage":"fa-beer","intStatusId":1,"intLanguageId":1},{"intPOIId":14,"strPOIName":"Pizzaria","strPOIImage":"fa-pie-chart","intStatusId":1,"intLanguageId":1},{"intPOIId":15,"strPOIName":"Univesidade","strPOIImage":"fa-university","intStatusId":1,"intLanguageId":1},{"intPOIId":16,"strPOIName":"Hospital","strPOIImage":"fa-plus-square","intStatusId":1,"intLanguageId":1}]} </code></pre> <p>And my Java Code:</p> <pre><code>import com.android.volley.NoConnectionError; import com.android.volley.ServerError; import com.game.code.guide44.adapter.POIAdapter; import com.game.code.guide44.app.AppController; import com.game.code.guide44.data.PointOfInterest; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.android.volley.Request.Method; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.VolleyLog; import com.android.volley.toolbox.JsonObjectRequest; import android.app.Activity; import android.app.ProgressDialog; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ListView; import android.widget.Toast; public class POIChoose extends Activity { private ListView lVwPOI; private POIAdapter adapterPOI; private ProgressDialog pDialog; private List&lt;PointOfInterest&gt; POIList; private String url; private StringBuilder stbCheckedPOI; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_poi_choose); //Initialize with ListView object from activity_poi_choose by id lVwPOI = (ListView)findViewById(R.id.lvwPOI); //Initialize the list of POI POIList = new ArrayList&lt;PointOfInterest&gt;(); //initialize with POI List adapterPOI = new POIAdapter(this, POIList); //Fill the LiistView with POIAdapter content lVwPOI.setAdapter(adapterPOI); stbCheckedPOI = new StringBuilder(); //Base url //Change "1" to dynamic user language url = getString(R.string.urlBase)+getString(R.string.urlGetPOI)+"?ff_01="+String.format(getString(R.string.sqlSelectPOI), "1"); //Initialize the ProgressDialog pDialog = new ProgressDialog(POIChoose.this); //Show the progress bar befores making HTTP request pDialog.setMessage(getString(R.string.txtMsgPleaseWait)); pDialog.show(); // making fresh volley request and getting json JsonObjectRequest jsonReq = new JsonObjectRequest(Method.GET, url, null, new Response.Listener&lt;JSONObject&gt;() { @Override public void onResponse(JSONObject response) { VolleyLog.v("VOLLEY", "Response: " + response.toString()); if (response != null) { parseJsonFeed(response); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { if(error instanceof NoConnectionError) Toast.makeText(POIChoose.this, "No internet available", Toast.LENGTH_SHORT).show(); else if(error instanceof ServerError) Toast.makeText(POIChoose.this, "Server Error", Toast.LENGTH_SHORT).show(); VolleyLog.e("VOLLEY_ERROR", "Error: " + error.getMessage()); Log.e("LOG", "Error: " + error.getMessage()); pDialog.dismiss(); } }); // Adding request to volley request queue AppController.getInstance().addToRequestQueue(jsonReq); } @Override public void onDestroy() { super.onDestroy(); hidePDialog(); } private void hidePDialog() { if (pDialog != null) { pDialog.dismiss(); pDialog = null; } } private void parseJsonFeed(JSONObject response){ try{ JSONArray jsonArray = response.getJSONArray("arrPOI"); for (int i = 0; i &lt; response.length(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.get(i); PointOfInterest Poi = new PointOfInterest(); Poi.setPOIId(jsonObject.getInt("intPointId")); Poi.setPOIName(jsonObject.getString("vchPointName")); Poi.setPOIPicture(jsonObject.getString("vchAwesomeFont")); Poi.setStatusId(jsonObject.getInt("intStatusId")); Poi.setLanguageId(jsonObject.getInt("intLanguageId")); // adding movie to movies array POIList.add(Poi); } } catch(JSONException e){ e.printStackTrace(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_first_choose, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } public void performSelectPOI(View view){ for(int i = 0; i &lt; POIList.size(); i++) { if(adapterPOI.mCheckStates.get(i)==true) { stbCheckedPOI.append(POIList.get(i).toString()); stbCheckedPOI.append(" "); } else { } } Toast.makeText(AppController.getContext(), stbCheckedPOI, Toast.LENGTH_LONG).show(); } } </code></pre> <p>I also heard about <strong><em>GSON</em></strong>. Is it the solution? Can anyone help me? Thanks in advance!!</p> </div>

使用JSONObject的fromObject方法转换成JsonObject对象时

使用JSONObject的fromObject方法转换成JsonObject对象时,在对象中有Date类型的属性,且值为null,然后就报空指针异常了 net.sf.json.JSONException: java.lang.NullPointerException at net.sf.json.JSONObject._fromBean(JSONObject.java:987) at net.sf.json.JSONObject.fromObject(JSONObject.java:168)

@RequestBody 实体类接收不到数据,但是用com.alibaba.fastjson.JSONObject可以

``` @RequestMapping(value = "/getTest", method = {RequestMethod.POST}) public @ResponseBody CommonResponse getTest(@RequestBody TestForm form { ``` 后台这样写,使用postman测试 请求会直接报400, ``` <!doctype html> <html lang="en"> <head> <title>HTTP Status 400 – Bad Request</title> <style type="text/css"> h1 { font-family: Tahoma, Arial, sans-serif; color: white; background-color: #525D76; font-size: 22px; } h2 { font-family: Tahoma, Arial, sans-serif; color: white; background-color: #525D76; font-size: 16px; } h3 { font-family: Tahoma, Arial, sans-serif; color: white; background-color: #525D76; font-size: 14px; } body { font-family: Tahoma, Arial, sans-serif; color: black; background-color: white; } b { font-family: Tahoma, Arial, sans-serif; color: white; background-color: #525D76; } p { font-family: Tahoma, Arial, sans-serif; background: white; color: black; font-size: 12px; } a { color: black; } a.name { color: black; } .line { height: 1px; background-color: #525D76; border: none; } </style> </head> <body> <h1>HTTP Status 400 – Bad Request</h1> <hr class="line" /> <p><b>Type</b> Status Report</p> <p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). </p> <hr class="line" /> <h3>Apache Tomcat/8.5.42</h3> </body> </html> ``` 如果后台改为 ``` public CommonResponse getTest(@RequestBody JSONObject jsonObject) { ``` 用JSONObject接收则没有问题,请各位大佬告知原因

org.json.JSONException值类型java.lang.String无法转换为JSONObject

<div class="post-text" itemprop="text"> <p>I'm trying to make a login/register app and when i run the code i get this error and my code doesn't work. What am i doing wrong? how can i solve this? If additional code is needed i can provide. Also if this question has a response already can you guide me to that response? I'm trying to find a solution to this problem since 2 days ago and can't seem to find what the problem is. I'm quite new to coding so any help is welcomed.</p> <p><strong>db_connect.php</strong></p> <pre><code>&lt;?php define('DB_USER', "root"); // db user define('DB_PASSWORD', ""); // db password (mention your db password here) define('DB_DATABASE', "member"); // database name define('DB_SERVER', "localhost"); // db server $con = mysqli_connect(DB_SERVER,DB_USER,DB_PASSWORD,DB_DATABASE); // Check connection if(mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?&gt; </code></pre> <p><strong>Function.php</strong></p> <pre><code>&lt;?php $random_salt_length = 32; /** * Queries the database and checks whether the user already exists * * @param $username * * @return */ function userExists($username){ $query = "SELECT username FROM member WHERE username = ?"; global $con; if($stmt = $con-&gt;prepare($query)){ $stmt-&gt;bind_param("s",$username); $stmt-&gt;execute(); $stmt-&gt;store_result(); $stmt-&gt;fetch(); if($stmt-&gt;num_rows == 1){ $stmt-&gt;close(); return true; } $stmt-&gt;close(); } return false; } function concatPasswordWithSalt($password,$salt){ global $random_salt_length; if($random_salt_length % 2 == 0){ $mid = $random_salt_length / 2; } else{ $mid = ($random_salt_length - 1) / 2; } return substr($salt,0,$mid - 1).$password.substr($salt,$mid,$random_salt_length - 1); } ?&gt; </code></pre> <p><strong>Login.php</strong></p> <pre><code>&lt;?php $response = array(); include 'db/db_connect.php'; include 'functions.php'; //Get the input request parameters $inputJSON = file_get_contents('php://input'); $input = json_decode($inputJSON); //convert JSON into array //Check for Mandatory parameters if(isset($input-&gt;username) &amp;&amp; isset($input-&gt;password)){ $username = $input-&gt;username; $password = $input-&gt;password; $query = "SELECT full_name,password_hash, salt FROM member WHERE username = ?"; if($stmt = $con-&gt;prepare($query)){ $stmt-&gt;bind_param("s",$username); $stmt-&gt;execute(); $stmt-&gt;bind_result($fullName,$passwordHashDB,$salt); if($stmt-&gt;fetch()){ //Validate the password if(password_verify(concatPasswordWithSalt($password,$salt),$passwordHashDB)){ $response["status"] = 0; $response["message"] = "Login successful"; $response["full_name"] = $fullName; } else{ $response["status"] = 1; $response["message"] = "Invalid username and password combination"; } } else{ $response["status"] = 1; $response["message"] = "Invalid username and password combination"; } $stmt-&gt;close(); } } else{ $response["status"] = 2; $response["message"] = "Missing mandatory parameters"; } //Display the JSON response echo json_encode($response); ?&gt; </code></pre> <p><strong>Register.php</strong></p> <pre class="lang-php prettyprint-override"><code>&lt;?php $response = array(); include 'db/db_connect.php'; include 'Functions.php'; //Get the input request parameters $inputJSON = file_get_contents('php://input'); $input = json_decode($inputJSON, TRUE); //convert JSON into array //Check for Mandatory parameters if(isset($input['username']) &amp;&amp; isset($input['password']) &amp;&amp; isset($input['full_name'])){ $username = $input['username']; $password = $input['password']; $fullName = $input['full_name']; //Check if user already exist if(!userExists($username)){ //Get a unique Salt $salt = getSalt(); //Generate a unique password Hash $passwordHash = password_hash(concatPasswordWithSalt($password,$salt),PASSWORD_DEFAULT); //Query to register new user $insertQuery = "INSERT INTO member(username, full_name, password_hash, salt) VALUES (?,?,?,?)"; if($stmt = $con-&gt;prepare($insertQuery)){ $stmt-&gt;bind_param("ssss",$username,$fullName,$passwordHash,$salt); $stmt-&gt;execute(); $response["status"] = 0; $response["message"] = "User created"; $stmt-&gt;close(); } } else{ $response["status"] = 1; $response["message"] = "User exists"; } } else{ $response["status"] = 2; $response["message"] = "Missing mandatory parameters"; } echo json_encode($response); ?&gt; </code></pre> <p>RegisterActivity.java</p> <pre class="lang-java prettyprint-override"><code>package com.example.activitymanagement; import android.app.ProgressDialog; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.JsonObjectRequest; import org.json.JSONException; import org.json.JSONObject; public class RegisterActivity extends AppCompatActivity { private static final String KEY_STATUS = "status"; private static final String KEY_MESSAGE = "message"; private static final String KEY_FULL_NAME = "full_name"; private static final String KEY_USERNAME = "username"; private static final String KEY_PASSWORD = "password"; private static final String KEY_EMPTY = ""; private EditText etUsername; private EditText etPassword; private EditText etConfirmPassword; private EditText etFullName; private String username; private String password; private String confirmPassword; private String fullName; private ProgressDialog pDialog; private String register_url = "http://10.0.2.2/member/register.php"; private SessionHandler session; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); session = new SessionHandler(getApplicationContext()); setContentView(R.layout.activity_register); etUsername = findViewById(R.id.etUsername); etPassword = findViewById(R.id.etPassword); etConfirmPassword = findViewById(R.id.etConfirmPassword); etFullName = findViewById(R.id.etFullName); Button login = findViewById(R.id.btnRegisterLogin); Button register = findViewById(R.id.btnRegister); //Launch Login screen when Login Button is clicked login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(RegisterActivity.this, LoginActivity.class); startActivity(i); finish(); } }); register.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Retrieve the data entered in the edit texts username = etUsername.getText().toString().toLowerCase().trim(); password = etPassword.getText().toString().trim(); confirmPassword = etConfirmPassword.getText().toString().trim(); fullName = etFullName.getText().toString().trim(); if (validateInputs()) { registerUser(); } } }); } /** * Display Progress bar while registering */ private void displayLoader() { pDialog = new ProgressDialog(RegisterActivity.this); pDialog.setMessage("Signing Up.. Please wait..."); pDialog.setIndeterminate(false); pDialog.setCancelable(false); pDialog.show(); } /** * Launch Dashboard Activity on Successful Sign Up */ private void loadDashboard() { Intent i = new Intent(getApplicationContext(), DashboardActivity.class); startActivity(i); finish(); } private void registerUser() { displayLoader(); JSONObject request = new JSONObject(); try { //Populate the request parameters request.put(KEY_USERNAME, username); request.put(KEY_PASSWORD, password); request.put(KEY_FULL_NAME, fullName); } catch (JSONException e) { e.printStackTrace(); } JsonObjectRequest jsArrayRequest = new JsonObjectRequest (Request.Method.POST, register_url, request, new Response.Listener&lt;JSONObject&gt;() { @Override public void onResponse(JSONObject response) { pDialog.dismiss(); try { //Check if user got registered successfully if (response.getInt(KEY_STATUS) == 0) { //Set the user session session.loginUser(username,fullName); loadDashboard(); }else if(response.getInt(KEY_STATUS) == 1){ //Display error message if username is already existsing etUsername.setError("Username already taken!"); etUsername.requestFocus(); }else{ Toast.makeText(getApplicationContext(), response.getString(KEY_MESSAGE), Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { pDialog.dismiss(); //Display error message whenever an error occurs Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show(); } }); // Access the RequestQueue through your singleton class. MySingleton.getInstance(this).addToRequestQueue(jsArrayRequest); } /** * Validates inputs and shows error if any * @return */ private boolean validateInputs() { if (KEY_EMPTY.equals(fullName)) { etFullName.setError("Full Name cannot be empty"); etFullName.requestFocus(); return false; } if (KEY_EMPTY.equals(username)) { etUsername.setError("Username cannot be empty"); etUsername.requestFocus(); return false; } if (KEY_EMPTY.equals(password)) { etPassword.setError("Password cannot be empty"); etPassword.requestFocus(); return false; } if (KEY_EMPTY.equals(confirmPassword)) { etConfirmPassword.setError("Confirm Password cannot be empty"); etConfirmPassword.requestFocus(); return false; } if (!password.equals(confirmPassword)) { etConfirmPassword.setError("Password and Confirm Password does not match"); etConfirmPassword.requestFocus(); return false; } return true; } } </code></pre> </div>

错误解析数据:org.json.JSONException:值<!DOCTYPE类型java.lang.String无法转换为JSONObject

<div class="post-text" itemprop="text"> <p>The URL that I use to get JSON from redirects the URL to recaptcha and gives the following error: "data org.json.JSONException: Value <code>&lt;!DOCTYPE of type java.lang.String cannot be converted to JSONObject</code>" </p> <p>Following is the activity and the code has the url i am trying to get JSON from but instead i get redirected to recaptcha:</p> <pre><code>protected Void doInBackground(Void... params) { // Create an array arraylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); // Retrieve JSON Objects from the given URL address //URL jsonobject = JSONfunctions .getJSONfromURL("http://laboneinside.com/android/diag_conn.php"); try { // Locate the array name in JSON jsonarray = jsonobject.getJSONArray("result"); Log.i("JSON TAG", jsonobject.toString()); for (int i = 0; i &lt; jsonarray.length(); i++) { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); jsonobject = jsonarray.getJSONObject(i); // Retrive JSON Objects map.put("nameDiag", jsonobject.getString("name")); map.put("srcDiag", jsonobject.getString("src")); map.put("linkDiag", jsonobject.getString("link")); // Set the JSON Objects into the array arraylist.add(map); } } catch (JSONException e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return null; } </code></pre> <p>JSONFUNCTION:</p> <pre><code>public class JSONfunctions { public static JSONObject getJSONfromURL(String url) { InputStream is = null; String result = ""; JSONObject jArray = null; // Download JSON data from URL try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e("log_tag", "Error in http connection " + e.toString()); } // Convert response to string try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + " "); } is.close(); result = sb.toString(); Log.i("JSON Parser", result); } catch (Exception e) { Log.e("log_tag", "Error converting result " + e.toString()); } try { jArray = new JSONObject(result); } catch (JSONException e) { Log.e("log_tag", "Error parsing data " + e.toString()); } return jArray; } } </code></pre> <p>Following is the logcat:</p> <pre><code>I/JSON Parser: &lt;!DOCTYPE html&gt; &lt;!--[if lt IE 7]&gt; &lt;html class="no-js ie6 oldie" lang="en-US"&gt; &lt;![endif]--&gt; &lt;!--[if IE 7]&gt; &lt;html class="no-js ie7 oldie" lang="en-US"&gt; &lt;![endif]--&gt; &lt;!--[if IE 8]&gt; &lt;html class="no-js ie8 oldie" lang="en-US"&gt; &lt;![endif]--&gt; &lt;!--[if gt IE 8]&gt;&lt;!--&gt; &lt;html class="no-js" lang="en-US"&gt; &lt;!--&lt;![endif]--&gt; &lt;head&gt; &lt;title&gt;Attention Required! | CloudFlare&lt;/title&gt; &lt;meta charset="UTF-8" /&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" /&gt; &lt;meta name="robots" content="noindex, nofollow" /&gt; &lt;meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" /&gt; &lt;link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/cf.errors.css" type="text/css" media="screen,projection" /&gt; &lt;!--[if lt IE 9]&gt;&lt;link rel="stylesheet" id='cf_styles-ie-css' href="/cdn-cgi/styles/cf.errors.ie.css" type="text/css" media="screen,projection" /&gt;&lt;![endif]--&gt; &lt;style type="text/css"&gt;body{margin:0;padding:0}&lt;/style&gt; &lt;!--[if lte IE 9]&gt;&lt;script type="text/javascript" src="/cdn-cgi/scripts/jquery.min.js"&gt;&lt;/script&gt;&lt;![endif]--&gt; &lt;!--[if gte IE 10]&gt;&lt;!--&gt;&lt;script type="text/javascript" src="/cdn-cgi/scripts/zepto.min.js"&gt;&lt;/script&gt;&lt;!--&lt;![endif]--&gt; &lt;script type="text/javascript" src="/cdn-cgi/scripts/cf.common.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="cf-wrapper"&gt; &lt;div class="cf-alert cf-alert-error cf-cookie-error" id="cookie-alert" data-translate="enable_cookies"&gt;Please enable cookies.&lt;/div&gt; &lt;div id="cf-error-details" class="cf-error-details-wrapper"&gt; &lt;div class="cf-wrapper cf-header cf-error-overview"&gt; &lt;h1 data-translate="challenge_headline"&gt;One more step&lt;/h1&gt; &lt;h2 class="cf-subheadline"&gt;&lt;span data-translate="complete_sec_check"&gt;Please complete the security check to access&lt;/span&gt; laboneinside.com&lt;/h2&gt; &lt;/div&gt;&lt;!-- /.header --&gt; &lt;div class="cf-section cf-highlight cf-captcha-container"&gt; &lt;div class="cf-wrapper"&gt; &lt;div class="cf-columns two"&gt; &lt;div class="cf-column"&gt; &lt;div class="cf-highlight-inverse cf-form-stacked"&gt; &lt;form class="challenge-form" id="challenge-form" action="/cdn-cgi/l/chk_captcha" method="get"&gt; &lt;script type="text/javascript" src="/cdn-cgi/scripts/cf.challenge.js" data-type="normal" data-ray="308cf17ac17329be" async data-sitekey="6LfOYgoTAAAAAInWDVTLSc8Yibqp-c9DaLimzNGM" data-stoken="kvvwvLSUth2MQ7fsfXFwr9TjwkJ6pEiMAfiAhb7x9fVk7yqCvGMh-myXoKQuhQt_4MjgZHunito0fikCnHS-DFoymBKWm5gb3lnlB4dceb0"&gt;&lt;/script&gt; &lt;div class="g-recaptcha"&gt;&lt;/div&gt; &lt;noscript id="cf-captcha-bookmark" class="cf-captcha-info"&gt; &lt;div&gt;&lt;div style="width: 302px"&gt; &lt;div&gt; &lt;iframe src="https://www.google.com/recaptcha/api/fallback?k=6LfOYgoTAAAAAInWDVTLSc8Yibqp-c9DaLimzNGM&amp;stoken=kvvwvLSUth2MQ7fsfXFwr9TjwkJ6pEiMAfiAhb7x9fVk7yqCvGMh-myXoKQuhQt_4MjgZHunito0fikCnHS-DFoymBKWm5gb3lnlB4dceb0" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"&gt;&lt;/iframe&gt; &lt;/div&gt; &lt;div style="width: 300px; border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px;"&gt; &lt;textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid #c1c1c1; margin: 10px 25px; padding: 0px; resize: none;"&gt;&lt;/textarea&gt; &lt;input type="submit" value="Submit"&gt;&lt;/input&gt; &lt;/div&gt; &lt;/div&gt;&lt;/div&gt; &lt;/noscript&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="cf-column"&gt; &lt;div class="cf-screenshot-container"&gt; &lt;span class="cf-no-screenshot"&gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;!-- /.columns --&gt; &lt;/div&gt; &lt;/div&gt;&lt;!-- /.captcha-container --&gt; &lt;div class="cf-section cf-wrapper"&gt; &lt;div class="cf-columns two"&gt; &lt;div class="cf-column"&gt; &lt;h2 data-translate="why_captcha_headline"&gt;Why do I have to complete a CAP 11-28 04:55:15.976 30265-30325/com.example.predator.labone E/log_tag: Error parsing data org.json.JSONException: Value &lt;!DOCTYPE of type java.lang.String cannot be converted to JSONObject </code></pre> <p>How do i stop it from redirecting so that i can get to the page that has the JSON data?</p> </div>

list转json出现警告的问题

需求是按照easyui来转json。代码是这样的 JSONObject jsonObj = new JSONObject(); jsonObj.put("total",total ); jsonObj.put("rows", list); total是总页数,list是数据集合。 但是控制台一直有warning net.sf.json.JSONObject - Property 'callback' has no read method. SKIPPED list有多少条数据就有多少个warning。callback我没有定义这个 属性。 这个不影响项目的运行,但是老是打印控制台和log4j文件,就很头疼了。 json导包是net.sf.json.JSONObject; jar是json-lib-2.2.1-jdk15.jar 请问怎么不让它打印。谢谢

Android代码Value of type java.lang.String cannot be converted to JSONObject

在创建jsonObject对象时报错,result是发送poast请求返回的json内容 JSONObject jsonObject = new JSONObject(result); 试了网上说的什么UTF-8 BOM头的问题的方法还是不行, 哪位大神帮忙看一下 W/System.err: org.json.JSONException: Value {"mid":"004YVmzL0O67WR","m4a":"http:\/\/dl.stream.mmmusic.gg.com\/C400004YVmzL0O67WR.m4a?guid=2095717240&skey=CC1743DB70C0AFD81B6CD9A4826F619D0A60FBF859D5238D87EEA2DDEB50D1D6BF1732FDFB30E6C70648F4A57CBC2BAC740D22E1F7D2ED88&uin=0&fromtag=38","mp3_l":"http:\/\/dl.stream.mmmusic.gg.com\/M500004YVmzL0O67WR.mp3?guid=2095717240&skey=CC1743DB70C0AFD81B6CD9A4826F619D0A60FBF859D5238D87EEA2DDEB50D1D6BF1732FDFB30E6C70648F4A57CBC2BAC740D22E1F7D2ED88&uin=0&fromtag=53","mp3_h":"http:\/\/dl.stream.mmmusic.gg.com\/M800004YVmzL0O67WR.mp3?guid=2095717240&skey=CC1743DB70C0AFD81B6CD9A4826F619D0A60FBF859D5238D87EEA2DDEB50D1D6BF1732FDFB30E6C70648F4A57CBC2BAC740D22E1F7D2ED88&uin=0&fromtag=53","ape":"http:\/\/dl.stream.mmmusic.gg.com\/A000004YVmzL0O67WR.ape?guid=2095717240&skey=CC1743DB70C0AFD81B6CD9A4826F619D0A60FBF859D5238D87EEA2DDEB50D1D6BF1732FDFB30E6C70648F4A57CBC2BAC740D22E1F7D2ED88&uin=0&fromtag=53","flac":"http:\/\/dl.stream.mmmusic.gg.com\/F000004YVmzL0O67WR.flac?guid=2095717240&skey=CC1743DB70C0AFD81B6CD9A4826F619D0A60FBF859D5238D87EEA2DDEB50D1D6BF1732FDFB30E6C70648F4A57CBC2BAC740D22E1F7D2ED88&uin=0&fromtag=53","songname":"\u7ae5\u8bdd\u9547","albumname":"\u7ae5\u8bdd\u9547","singername":"\u8bb8\u5a1c","pic":"https:\/\/y.gtimg.cn\/music\/photo_new\/T002R300x300M000000fglnt1hPvpJ.jpg?max_age=2592000"} of type java.lang.String cannot be converted to JSONObject W/System.err: at org.json.JSON.typeMismatch(JSON.java:112) at org.json.JSONObject.<init>(JSONObject.java:163) at org.json.JSONObject.<init>(JSONObject.java:176)

JSONObject cannot be cast to org.json.JSONArray

![图片说明](https://img-ask.csdn.net/upload/201610/08/1475930733_258992.png) ![图片说明](https://img-ask.csdn.net/upload/201610/08/1475930743_863142.png) ![图片说明](https://img-ask.csdn.net/upload/201610/08/1475930752_144222.png) 我知道这是JSONObject解析了JSONArray,但是我改过来之后就无法获取服务器的值了

关于JSONObject.fromObject()方法

如果参数A存在实体类B的引用,而B又存在A 的引用,这该怎么办?

JSONOject对象中has方法与containskey 方法的区别?

项目开发中,使用JSONObject解析json消息,判断json消息中是否包括某个key时,使用has方法、containskey方法都能实现。但是想知道这两个方法有什么区别,或有什么优劣。在官方文档中查阅,只找到了has方法的介绍:Determine if the JSONObject contains a specific key. 望知道的大牛帮忙解惑。

JSONObject.fromObject()方法调用出错

在try这个语句块中调用JSONObject.fromObject(obj) 这个方法, 不走catch,直接走finally

java bean对象使用JSONObject.fromObject字段内容被截断

今天做项目时,java bean对象使用JSONObject.fromObject转化为JSONObject的时候,bean中字段a中是一些html文本内容,比较长,会有5000多字符左右,也不算很多,但序列化成JSONObject之后,key a中的值被截断了一半左右,后来换成其他字符串做实验,发现只要字符串过长,转化为JSONObject后就会被截断。。。不知道为什么,求解

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

Linux面试题(2020最新版)

文章目录Linux 概述什么是LinuxUnix和Linux有什么区别?什么是 Linux 内核?Linux的基本组件是什么?Linux 的体系结构BASH和DOS之间的基本区别是什么?Linux 开机启动过程?Linux系统缺省的运行级别?Linux 使用的进程间通信方式?Linux 有哪些系统日志文件?Linux系统安装多个桌面环境有帮助吗?什么是交换空间?什么是root帐户什么是LILO?什...

Linux命令学习神器!命令看不懂直接给你解释!

大家都知道,Linux 系统有非常多的命令,而且每个命令又有非常多的用法,想要全部记住所有命令的所有用法,恐怕是一件不可能完成的任务。 一般情况下,我们学习一个命令时,要么直接百度去搜索它的用法,要么就直接用 man 命令去查看守冗长的帮助手册。这两个都可以实现我们的目标,但有没有更简便的方式呢? 答案是必须有的!今天给大家推荐一款有趣而实用学习神器 — kmdr,让你解锁 Linux 学习新姿势...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

史上最全的 python 基础知识汇总篇,没有比这再全面的了,建议收藏

网友们有福了,小编终于把基础篇的内容全部涉略了一遍,这是一篇关于基础知识的汇总的文章,请朋友们收下,不用客气,不过文章篇幅肯能会有点长,耐心阅读吧爬虫(七十)多进程multiproces...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

85后蒋凡:28岁实现财务自由、34岁成为阿里万亿电商帝国双掌门,他的人生底层逻辑是什么?...

蒋凡是何许人也? 2017年12月27日,在入职4年时间里,蒋凡开挂般坐上了淘宝总裁位置。 为此,时任阿里CEO张勇在任命书中力赞: 蒋凡加入阿里,始终保持创业者的冲劲,有敏锐的...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

新一代神器STM32CubeMonitor介绍、下载、安装和使用教程

关注、星标公众号,不错过精彩内容作者:黄工公众号:strongerHuang最近ST官网悄悄新上线了一款比较强大的工具:STM32CubeMonitor V1.0.0。经过我研究和使用之...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

大学一路走来,学习互联网全靠这几个网站,最终拿下了一把offer

大佬原来都是这样炼成的

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

什么时候跳槽,为什么离职,你想好了么?

都是出来打工的,多为自己着想

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

你期望月薪4万,出门右拐,不送,这几个点,你也就是个初级的水平

先来看几个问题通过注解的方式注入依赖对象,介绍一下你知道的几种方式@Autowired和@Resource有何区别说一下@Autowired查找候选者的...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

立即提问
相关内容推荐