标签: jsonobject

Json对象的Volley Post方法

data={
    "request": {
       "type": "event_and_offer",
       "devicetype": "A"
    },
    "requestinfo": {
       "value": "offer"
      }
}
Run Code Online (Sandbox Code Playgroud)

如何从volley plz帮助发布此请求

            JsonObjectRequest jsonObjReq = new JsonObjectRequest(
            Request.Method.POST,url, null   ,
            new Response.Listener<JSONObject>() {




                @Override
                public void onResponse(JSONObject response) {
                    Log.d(TAG, response.toString());

                    msgResponse.setText(response.toString());
                    hideProgressDialog();
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    hideProgressDialog();
                }
            }) {

        /**
         * Passing some request headers
         * */
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>(); …
Run Code Online (Sandbox Code Playgroud)

post android android-volley jsonobject

6
推荐指数
1
解决办法
2万
查看次数

在spring restful webservice中返回JsonObject

我正在使用spring框架.我在Wepsphere服务器上有一个web服务

@RequestMapping (value="/services/SayHello2Me" , method=RequestMethod.GET, headers="Accept=application/json")
@ResponseBody
public JSONObject SayHello2Me(HttpServletRequest request) throws Exception {
    String input = (String) request.getParameter("name");
    String output = "hello " + input + " :)";
    JSONObject outputJsonObj = new JSONObject();
    outputJsonObj.put("output", output);
        return outputJsonObj;
      }
Run Code Online (Sandbox Code Playgroud)

当我将其称为Chrome,如http:// myserver/services/sayHello2Me?name = 'baris'时,它会返回该错误:

错误404:SRVE0295E:报告错误:404

如果我在我的webservice中更改注释

@RequestMapping (value="/services/SayHello2Me")
@ResponseBody
public JSONObject SayHello2Me(HttpServletRequest request) throws Exception {

    String input = (String) request.getParameter("name");
    String output = "hello " + input + " :)";
    JSONObject outputJsonObj = new JSONObject();
    outputJsonObj.put("output", output);

    return outputJsonObj; …
Run Code Online (Sandbox Code Playgroud)

java rest spring web-services jsonobject

6
推荐指数
1
解决办法
1万
查看次数

JSONObject删除空值对

这是我的Json文件:

{  
   "models":{},
   "path":[  
      {  
         "path":"/web-profiles",
         "operations":[  
            {  
               "type":"",
               "responseMessages":[]
            }
         ]
      }
   ],
   "produces":[]
}
Run Code Online (Sandbox Code Playgroud)

如果键的值为空(包括[],"",{}).如何从Json文件中删除这些对.

  1. 我尝试使用JSONObject内置函数来删除不必要的对.但是,它没有用.
  2. 我尝试使用字符串方法逐行处理它.它有太多的情况,我不能在我的代码中涵盖所有这些情况.(例如,子键'operations',当你想删除所有空值时,这个键(操作)值对也应该被删除.)任何想法?

java string format json jsonobject

6
推荐指数
1
解决办法
1万
查看次数

Android将String转换为JSONObject

我想将字符串转换为JSONObject.以下是示例代码.

String str = "{"time": 1449838598.0999202, "Label": "Shirt", "Price": 52}";
JSONObject obj = new JSONObject(str);
Run Code Online (Sandbox Code Playgroud)

但转换时间后变为1.4498385980999203E9.任何帮助将不胜感激.谢谢

android jsonobject

6
推荐指数
1
解决办法
946
查看次数

gson.toJson(对象)BigDecimal Precision Lost

当我将Object转换为Json时,我遇到了BigDecimal Precision丢失的问题.
让我说我有Pojo课,

public class DummyPojo {
    private BigDecimal amount;
    private String id;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public BigDecimal getAmount() {
        return amount;
    }
    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }
} 
Run Code Online (Sandbox Code Playgroud)

现在我正在为Pojo设置值,然后转换为JSON

public static void main(String[] args) {
        BigDecimal big = new BigDecimal("1000.0005");
        JSONObject resultJson = new JSONObject();
        DummyPojo summary = new DummyPojo();
        summary.setId("A001");
        summary.setAmount(big);

        resultJson.put("summary",new Gson().toJson(summary));
        String result = resultJson.toString();
        System.out.println(result);
    }
Run Code Online (Sandbox Code Playgroud)

第一次测试 - …

java json gson jsonobject

5
推荐指数
1
解决办法
4979
查看次数

将类转换为JSONObject

我有几个这样的课程.我想将类转换为JSONObject格式.

import java.io.Serializable;

import com.google.gson.annotations.SerializedName;

public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    @SerializedName("id")
    private Integer mId;
    @SerializedName("name")
    private String mName = "";
    @SerializedName("email")
    private String mEmail;

    public Integer getId() {
        return mId;
    }
    public void setId(Integer id) {
        mId = id;
    }

    public String getName() {
        return mName;
    }
    public void setName(String name) {
        mName = name;
    }

    public String getEmail() {
        return mEmail;
    }
    public void setEmail(String email) {
        mEmail = email;
    } …
Run Code Online (Sandbox Code Playgroud)

java json gson jsonobject

5
推荐指数
2
解决办法
4万
查看次数

统一读取和解析 C# 中的 Json 文件

这是代码

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;

public class csharpfile:MonoBehaviour{

    public void LoadJson()
    {
        using (StreamReader r = new StreamReader("file.json"))
        {
            string json = r.ReadToEnd();
            List<Item> items = JsonConvert.DeserializeObject<List<Item>>(json);


        }
    }

    public class Item
    {
        public int millis;
        public string stamp;
        public DateTime datetime;
        public string light;
        public float temp;
        public float vcc;
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我想解析文件内容(file.json)

[ 
    { "millis": "1000", 
      "stamp": "1273010254", 
      "datetime": "2010/5/4 21:57:34", 
      "light": "333", 
      "temp": "78.32", 
      "vcc": "3.54" }, 
] 
Run Code Online (Sandbox Code Playgroud)

文件解析后我将如何在屏幕上打印内容以及如何写入文件 .do help …

c# json unity-game-engine jsonobject

5
推荐指数
1
解决办法
2万
查看次数

根据对象将对象转换为 JSONObject 或 JSONArray 的方法

我一直在尝试这样的方法,但找不到任何解决方案:

public static JSONObject or JSONArray objectToJSON(Object object){
    if(object is a JSONObject)
        return new JSONObject(object)
    if(object is a JSONArray)
        return new JSONArray(object)
}
Run Code Online (Sandbox Code Playgroud)

我试过这个:

public static JSONObject objectToJSONObject(Object object){
    Object json = null;
    try {
        json = new JSONTokener(object.toString()).nextValue();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    JSONObject jsonObject = (JSONObject)json;
    return jsonObject;
}

public static JSONArray objectToJSONArray(Object object){
    Object json = null;
    try {
        json = new JSONTokener(object.toString()).nextValue();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    JSONArray jsonObject = (JSONArray)json;
    return …
Run Code Online (Sandbox Code Playgroud)

java android json casting jsonobject

5
推荐指数
1
解决办法
4万
查看次数

使用标题和Parametes Volley删除请求

嗨我想使用标题和身体参数使用Volley向服务器发送删除请求.但我无法成功发送请求

我试过的

JSONObject jsonbObjj = new JSONObject();
try {
    jsonbObjj.put("nombre", Integer.parseInt(no_of_addition
            .getText().toString()));
    jsonbObjj.put("cru", crue);
    jsonbObjj.put("annee", 2010);
} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
VolleyRequest mVolleyRequest = new VolleyRequest(
        Method.DELETE, url, jsonbObjj,

        new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject jsonObject) {
                // TODO Auto-generated method stub

                if (pDialog != null) {
                    pDialog.dismiss();
                }
                Log.e("Server Response", "response = "
                        + jsonObject.toString());
            }

        }, new ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError arg0) {
                // TODO Auto-generated method stub …
Run Code Online (Sandbox Code Playgroud)

android sql-delete android-volley jsonobject

5
推荐指数
1
解决办法
7367
查看次数

如何使用json对象输入来记录swagger查询参数

如何为in: query(不in: body)请求参数定义JSON对象值?

示例如下:

paths:
  /schedules:
    get:
      summary: Gets the list of schedules
      description: |
        The schedules endpoint returns information about the configured schedules.
      parameters:
        - name: filter
          in: query
          description: >
          Returns whether alert runs on matching schedule.


          Example request:


              {
                "type": "a",
                "start" : "b",
                "stop" : "c"
              }
          required: true
          type: string
Run Code Online (Sandbox Code Playgroud)

因为它不是in: body,我不能使用schema.

http-request-parameters jsonobject swagger-2.0

5
推荐指数
0
解决办法
278
查看次数