在收到通知时,我收到了下面提到的一些数据
Bundle[{google.sent_time=1233212221545, msg={"message":"You received a chat message","type":"Match Maker","request_id":"501"}, chat={"owner":0,"request_id":"501"}, from=148566781839, google.message_id=0:148354545211779676%c3fc9c6ff9fd7ecd, android.support.content.wakelockid=3, collapse_key=do_not_collapse}]
Run Code Online (Sandbox Code Playgroud)
从此我想要检索
message
Request_id
Owner
type
我试图像这样检索
String mes1 = extras.getString("chat");
Run Code Online (Sandbox Code Playgroud)
我得到了这些价值观
{"owner":0,"request_id":"501"}
Run Code Online (Sandbox Code Playgroud)
示例:从上面我想获取所有者和请求ID如何检索这些值.
这是我的代码:
public class GCMIntentService extends IntentService {
public static final int NOTIFICATION_ID = 1;
private static final String TAG = "GcmIntentService";
UserLocalStore userLocalStore;
private NotificationManager mNotificationManager;
public GCMIntentService() {
super("GcmIntentService");
}
Intent notificationIntent;
String type,token,requestid,notify_message;
Context context;
@Override
protected void onHandleIntent(Intent intent) {
userLocalStore = new UserLocalStore(this);
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = …
Run Code Online (Sandbox Code Playgroud) 我得到java.lang.RuntimeException: Stub!
异常,当我尝试解析String
到org.json.JSONObject
.我的Android API版本是19.
这是我的String
解析:
{
"url": "http://www.google.com",
"cookie": "012121",
"filename": "Google"
}
JSONObject jsonObject = new JSONObject(str); // getting exception at this line
String url = jsonObject.getString("url");
Run Code Online (Sandbox Code Playgroud) 我创建了一项活动,用于创建用户个人资料并存储其信息,例如姓名、ID、个人资料图片等。
该信息是唯一的,应该在应用程序的所有活动中使用。
我想知道创建一个存储所有信息并在所有活动中使用它的通用对象的最佳方法是什么。
我已阅读有关捆绑包和 JSON 的内容,但无法理解如何使用它。
请帮我看看我应该选择什么选项。我已经读了很多书,但现在还不确定。请帮助我了解什么是标准的做法以及什么会更好。
我已经使用volley创建了JSONRequest,它成功点击了服务,我检查了服务端,它接收了数据,然后发送"Success"作为回报.
问题在于,服务String
在输出中返回,而Volley JSON Data
在输出中除外.所以它执行onError
Method而不是onResponse
.
请指导我如何使其接受字符串响应,或者在您JSONObject
作为请求使用时不可能.
Request<JSONObject> jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, "http://192.168.0.101:8888/api/services/mytest",
jsonParent, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("Success", response.toString());
deleteFile();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error", error.toString());
deleteFile();
}
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
requestQueue.add(jsonObjectRequest);
Run Code Online (Sandbox Code Playgroud) android httprequest android-layout android-volley android-json
我想发布以下 JSON,
{
"name": {
"firstName": "f_name",
"lastName": "l_name"
},
"password": "mypassword123",
"email": "test.mail@gmail.com"
}
Run Code Online (Sandbox Code Playgroud)
接口内部的注册方法是,
@POST("user/createuser")
Call<RegisterResponseModel> register(@Body RegisterModel body);
Run Code Online (Sandbox Code Playgroud)
使用注册方法,如,
Name name = new Name("f_name", "l_name");
RegisterModel registerModel = new RegisterModel(name, "mypassword123", "test.mail@gmail.com");
Call<RegisterResponseModel> res = apiService.register(registerModel);
Run Code Online (Sandbox Code Playgroud)
但无法达到我想要的,请帮助我实现我所需要的。提前致谢
我正在尝试将一个DateTime
参数发送到通过JSON编码的WCF RESTful服务公开的方法.请求如下所示:
POST http://IP:PORT/LogService/json/GetLogEntriesByModule HTTP/1.1
Content-Length: 100
Content-Type: application/json
Host: IP:PORT
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
Expect: 100-Continue
{"maxentries":10,"upperdate":"1280703601462","lowerdate":"1277938801462","module":"Windows Service"}
Run Code Online (Sandbox Code Playgroud)
我尝试了几种格式DateTime
:
2010-07-01T10:54:00
(由WCFTestClient
应用程序通过NET.TCP 发送,它得到结果\/Date(12345678+0100)\/
01.07.2010 10:54:00
方法定义:
LogEntry[] GetLogEntriesByModule(
string module,
DateTime lowerDate,
DateTime upperDate,
int maxEntries,
out bool maxEntriesReached
)
Run Code Online (Sandbox Code Playgroud)
我总是得到以下回应:
HTTP/1.1 200 OK
Content-Length: 60
Content-Type: application/json; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 02 Jul 2010 09:07:04 GMT
{"GetLogEntriesByModuleResult":[],"maxEntriesReached":false}
Run Code Online (Sandbox Code Playgroud)
似乎DateTime
没有正确解析,因为Llog中有几个条目.
有谁知道如何做到这一点?
更新:问题出在服务器端并且已经解决.
我需要帮助解析简单的JSONArray,如下所示:
{
"text":[
"Morate popuniti polje tekst."
]
}
Run Code Online (Sandbox Code Playgroud)
我试过这个但是我失败了:
if (response_str != null) {
try {
JSONObject jsonObj = new JSONObject(response_str);
JSONArray arrayJson = jsonObj.getJSONArray("text");
for (int i = 0; i < arrayJson.length(); i++) {
JSONObject obj = arrayJson.optJSONObject(i);
error = obj.getString("text");
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用自定义 Facebook 登录按钮。这是我的代码。我正在使用会话管理器来存储整个应用程序的电子邮件和名称。我在第三个活动中使用了注销按钮。
如何从 Facebook 注销
public void FB_Login(View view){
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email"));
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// AccessToken.getCurrentAccessToken().getPermissions();
// Profile profile = Profile.getCurrentProfile();
// String firstName = profile.getFirstName();
// System.out.println(profile.getProfilePictureUri(20,20));
// System.out.println(profile.getLinkUri());
// App code
AccessToken.getCurrentAccessToken().getPermissions();
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
try {
email = object.getString("email");
name=object.getString("name");
// Creating user login session
// For testing …
Run Code Online (Sandbox Code Playgroud) 我试图从事先收到的JSON代码中搜索..
我想知道有没有有效的方法来搜索特定的对象?或者我应该像循环和if语句一样使用直接搜索?
我已成功解析JSON,并将其存储在我的String变量中.. JSON包含对象数组..
现在我想搜索特定的ObjectName并获取整个对象.. JSON就像
[
{
"name":"blank",
"date":"2014-06-05T00:44:30Z",
"boolean":null,
},
{
"name":"hello",
"date":"2013-05-04T00:43:20Z",
"boolean":null,
}
]
Run Code Online (Sandbox Code Playgroud)
我想搜索name ="hello"并返回最后一个Array
谁能告诉我怎么样?
非常感谢!
我有一个简单的活动,启动文件选择器,然后通过Android梁发送文件,如下所示:
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode==0 && resultCode==RESULT_OK) {
adapter.setBeamPushUris(new Uri[] {data.getData()}, this);
Button btn=new Button(this);
btn.setText("Done");
btn.setOnClickListener(this);
setContentView(btn);
}
}
Run Code Online (Sandbox Code Playgroud)
该活动能够正确地发送图像和.txt文件.但是,当我发送.json文件时,我得到"梁没有完成".
我认为这是因为,接收器上没有应用程序查看json文件,所以我创建了另一个版本来查看收到的txt文件.清单有
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
当我将json文件的扩展名更改为.txt时,文件正确发送,接收应用程序启动.但是当我将扩展名更改回.json并将接收器的mimetype更改为"application/json"时,我仍然得到"Beam not not complete"消息.
有什么想法吗?
谢谢!
android ×10
android-json ×10
json ×4
android-beam ×1
datetime ×1
gson ×1
httprequest ×1
java ×1
jsonobject ×1
nfc ×1
object ×1
rest ×1
retrofit ×1
search ×1
wcf ×1