小编Gre*_*nis的帖子

.NET Web API将JSON反序列化为对象

我超越了一个公司为我们开发的项目,遗憾的是我们没有得到太多支持,从长远来看,我们应该为自己完成维护.该应用程序包含一个简单的Web客户端(HTTP,JavaScript,Knockout框架)和REST API服务(.NET 4.5,我猜是ASP.NET MVC).

目前我只修改客户端,因此服务器仍应按预期工作.

在客户端,我稍微修改了Knockout View Model(添加了一些可计算和一些值的优化表示).视图模型由"问题"和"评论"组成(作为问题的数组,实际上是一个Bug跟踪器).如果我创建了一个新问题,则会将描述添加到第一个注释中,整个Model是JSON.stringified,并且发送到.NET API服务.我与Firebug一起证明,发布的JSON看起来像这样:

{
   "Id":0,
   "Title":"THis is a title",
   "Comments":[
       {
          "Id":1,
          "Text":"this is the first comment"
       }
   ]
}
Run Code Online (Sandbox Code Playgroud)

在客户端,我有一个"IssueController":

[HttpPost]
public HttpResponseMessage PostIssues( Issue issue ) {
   //issue should already hold the deserialized content of the JSON here,
   //but it only contains 'Id' and 'Title' not the 'Comments' (empty List)
   ...
}
Run Code Online (Sandbox Code Playgroud)

问题域模型对象也有一个用于保存注释的数组,但是为此它已经是空的..NET代码没有明确解析JSON的任何部分,据我所知,MVC框架通过相同的属性名称隐含地执行此操作(是吗?).

反序列化已按预期工作,因此.NET代码应该没问题,但我看起来我已经以某种方式修改了JSON,这种注释的隐式映射不再起作用.不幸的是,我没有很多.NET MVC框架的经验(或者它只是.NET WebAPI框架,甚至不能告诉你).

这些是我的问题:

  1. 那是什么样的.NET REST API框架?我该如何区分?
  2. 这种隐式JSON反序列化是如何工作的,以及它的缺陷是什么,例如当JSON的某些部分未按预期反序列化时?特别是在客户端(正如我所说,我没有修改服务器代码)
  3. 关于我可以对JSON做什么的任何想法,服务器不再喜欢它了?;)

编辑

Issue.cs看起来像这样(简化为肯定):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc json knockout.js

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

如何在Gradle构建中使用自定义proguard.jar?

我想在我的应用程序上运行proguard,其中包括Unity 3D.目前proguard尝试处理unity-classes.jar失败,唯一的解决方法是自己构建proguard并应用补丁(请参阅此链接获取错误报告).

所以,我现在有自己的自定义proguard.jar,但是如何让android插件使用呢?使用eclipse只需更换Android SDK目录中的proguard.jar,但这不再适用于Android Studio/Gradle.事实上,我可以从tools/proguard/lib /中删除proguard文件,它仍然可以运行!

如何让Android Studio/Gradle使用我自定义构建的proguard.jar?

android proguard gradle

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

在一个应用程序中使用2个或更多GCM Intent服务

我正在编写一个与Smooch和Carnival集成的应用程序.这两个库都使用定义GCM Intent Service接收消息的标准方法接收GCM推送消息.

当我只使用Smooch时,一切都很棒.当我只使用嘉年华时,一切都很棒.当我尝试使用两者时,问题就出现了.我发现GCM接收器只是启动定义intent的清单中列出的第一个服务com.google.android.c2dm.intent.RECEIVE.

实际上,我发现库中列出的库的顺序build.gradle会影响它们的清单合并到应用程序清单中的顺序.所以,如果我把smooch放在第一位,那就有效(但狂欢节没有收到任何东西).如果我把嘉年华放在第一位,那就有效(但是Smooch从来没有收到任何东西).

当我不控制任何一个时,如何处理多个GCM意图服务?通常,应用程序应如何定义和管理多个GCM意图服务?

android android-intent google-cloud-messaging smooch

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

当我向Parse提交新帖子时应用程序崩溃

这是我的应用程序崩溃的唯一地方,也是一个更重要的功能

LogCat告诉我:

java.lang.IllegalArgumentException:您必须使用ParseObject.create()或正确的子类创建此类型的ParseObject.在第37行.

我试过ParseObject.create()但是这引起了更多的问题(我可能做错了).我该如何编码呢?

这是我的newPost类:

public class newPost extends Activity {

private Button addButton;

private TextView postView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newpost);

    postView = ((EditText) findViewById(R.id.postView));

    addButton = ((Button) findViewById(R.id.addButton));
    addButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //line 37 Below
            ParseObject post = new ParseObject("Posts");
            post.put("content", postView);
            post.saveInBackground(new SaveCallback () {

                @Override
                public void done(ParseException e) {
                    if (e == null) {
                        setResult(RESULT_OK);
                        finish();
                    } else {
                        Toast.makeText(getApplicationContext(),
                                "Error saving: " + e.getMessage(), …
Run Code Online (Sandbox Code Playgroud)

android parse-platform

3
推荐指数
1
解决办法
2441
查看次数

Moshi 在 Kotlin 惰性属性上失败

当使用 Moshi 反序列化一个类时,它在by lazy属性上失败并出现错误:

IllegalArgumentException: No JsonAdapter for interface kotlin.Lazy annotated []
Run Code Online (Sandbox Code Playgroud)

所以我想告诉Moshi忽略这个属性。忽略这一点的方法显然是使用@Transient但是只能在字段上使用 - 而不是属性。

那么在使用 Moshi 反序列化时如何忽略 Kotlin 惰性属性呢?

android kotlin moshi

3
推荐指数
1
解决办法
727
查看次数

具有高度wrap_content的ConstraintLayout不适用于ImageView adjustViewBounds

我想创建这个:

线性布局布局

并且可以使用此LinearLayout执行此操作:

<LinearLayout android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white">

    <ImageView android:id="@+id/image"
        android:src="@drawable/image"
        android:adjustViewBounds="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:textSize="48sp"
        android:text="Hello World" />

</LinearLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

哪个效果很好.现在,我正在尝试使用ConstraintLayout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white">

    <ImageView android:id="@+id/image"
        android:src="@drawable/image"
        android:adjustViewBounds="true"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="48sp"
        android:text="Hello World"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/image" />

</android.support.constraint.ConstraintLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

不幸的是,这会产

使用ConstraintLayout进行布局尝试1

底部被切断了.问题是ConstraintLayout没有正确调整它的高度来尝试尊重adjustViewBounds图像.我已经看到了使用的建议,layout_constraintHeight_default并尝试过:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white">

    <ImageView android:id="@+id/image"
        android:src="@drawable/image"
        android:adjustViewBounds="true" …
Run Code Online (Sandbox Code Playgroud)

android android-constraintlayout

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

Android蓝牙打印在4.1上停止工作

我们有一个应用程序可以将图像打印到蓝牙打印机.这个应用程序在Android 4.0 ICS上运行良好但是当我们将其中一个升级到Android 4.1果冻bean时,打印在logcat中停止了这个工作:

W/System.err(19319):java.lang.SecurityException:Permission Denial:编写com.android.bluetooth.opp.BluetoothOppProvider uri内容://com.android.bluetooth.opp/btopp来自pid = 19319,uid = 10106需要android.permission.ACCESS_BLUETOOTH_SHARE或grantUriPermission()

问题是我们正在宣布该许可,所以这个错误对我们没有意义.这是我们清单中的一行

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.turner.itstrategy.LumenboxClient"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="11" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_BLUETOOTH_SHARE"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.VIBRATE" />

     (stuff removed)
</manifest>
Run Code Online (Sandbox Code Playgroud)

这是我们用来打印的代码.此代码取自stackoverflow和其他地方的示例.

ContentValues values = new ContentValues();

String path = Environment.getExternalStorageDirectory().toString();
File imageFile = new File(path, "CurrentLumenboxPrint.jpg");

//build the message to send on BT
values.put(BluetoothShare.URI, Uri.fromFile(imageFile).toString());
values.put(BluetoothShare.MIMETYPE, "image/jpeg");
values.put(BluetoothShare.DESTINATION, device.getAddress());
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis();
values.put(BluetoothShare.TIMESTAMP, ts);

// Here …
Run Code Online (Sandbox Code Playgroud)

android bluetooth

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