小编jud*_*ira的帖子

JSON.parse()等效于mongo驱动程序3.x for Java

JSON.parse() 来自mongo(Java驱动程序)返回BasicDBList或BasicDBObject.

但是,迁移到蒙戈司机3.x的时候,那是什么返回无论是新的解析方法Document还是List<Document>

在新驱动程序中,Document.parse()只解析一个对象,而不是一个数组(在给定数组时抛出异常).

对于具有3.x Java驱动程序的数组,JSON.parse()的等价物是什么?

java json mongodb mongodb-java

7
推荐指数
2
解决办法
4691
查看次数

如何在 Firefox 开发者控制台中禁用自动字符串转义?

来自 Chrome,我习惯于在开发人员 JS 控制台中生成非转义字符串:

\n
> JSON.stringify(JSON.parse('{"a": 10}'))\n{"a":10}\n
Run Code Online (Sandbox Code Playgroud)\n

\xe2\x80\x8b但是,在 Firefox 中,它会生成以下内容:

\n
> JSON.stringify(JSON.parse('{"a": 10}'))\n"{\\"a\\":10}"   <-- notice that the quote has been escaped as \\", which is correct, but not what I want\n
Run Code Online (Sandbox Code Playgroud)\n

\xe2\x80\x8b如何指示 Firefox 停止转义 JS 控制台中打印的字符串?

\n

javascript console firefox

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

android - 启动另一个应用程序的活动以获得它的结果

我有两个应用程序,A和B.

从A开始,我使用以下代码为结果启动B:

Intent fmIntent = getPackageManager().getLaunchIntentForPackage("com.example.B");
fmIntent.putExtra("hello", "world");
startActivityForResult(fmIntent, REQUEST_TEST);
Run Code Online (Sandbox Code Playgroud)

从B,我正在做以下事情:

getIntent().putExtra("completed", true);
setResult(RESULT_OK, getIntent());
finish();
Run Code Online (Sandbox Code Playgroud)

如果我在同一个应用程序中执行上述操作,则按预期工作.

但是,由于它有两个不同的应用程序,我收到一个空的意图,没有数据和未设置的结果代码.我应如何编辑上述内容以确保始终保持一个意图?

android launch android-intent android-activity

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

将带有 getLaunchIntentForPackage() 返回的意图的额外内容发送到另一个应用程序的主要活动

我正在尝试通过通知启动带有附加功能的应用程序。我使用以下方法获取它的启动意图:

Intent launchIntentForApp = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
Run Code Online (Sandbox Code Playgroud)

注意:上下文是同一个应用程序本身。我正在尝试构建一个可以在我的其他应用程序中使用的库。

我通过以下方式添加了一些额外内容:

launchIntentForApp.putExtra("test", true);
Run Code Online (Sandbox Code Playgroud)

然后我为它创建一个挂起的意图,并将其添加到通知抽屉中:

PendingIntent pIntent = PendingIntent.getActivity(context, 0, launchIntentForApp, 0);
Notification n = new Notification.Builder(context)
                    .setContentTitle(notifTitle)
                    .setContentText(notifMessage)
                    .setContentIntent(pIntent)
                    .setAutoCancel(true)
                    .setStyle(new Notification.BigTextStyle()
                            .bigText(notifMessage))
                    .setSmallIcon(R.color.transparent)
                    .build();
            NotificationManager notificationManager =
                    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(0, n);
Run Code Online (Sandbox Code Playgroud)

但是,当该应用程序的 Activity 启动时,在该 Activity 的 onCreate() 中,以下内容始终返回 null:

Bundle extras = getIntent().getExtras();
Run Code Online (Sandbox Code Playgroud)

我如何向该应用程序的主要活动发送额外信息?

android android-intent

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

Swift - 空数组的无限循环

我刚刚将我的项目从2.3升级到Swift 3.我所有的for循环都是无限的.我也可以在一个清新的游乐场重现它:

这是我正在做的事情:

var strs = [String!]()

strs.append("hello")
strs.append("world")

var count = 0
for s in strs {
    count += 1
}
Run Code Online (Sandbox Code Playgroud)

怎么了?在操场上,循环连续执行.

看看Apple的文档,这应该有用,不应该吗?

更新:如果我更改我的数组定义如下,它按预期工作.在数组中强制非可选值有什么害处?

var strs = [String]()
Run Code Online (Sandbox Code Playgroud)

更新2:这是一个已知的错误 - https://bugs.swift.org/browse/SR-1635

loops swift

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

iOS - 空翻译

使用正确的 XML 结构编辑从 Xcode 导出的 XLIFF 文件后,当我尝试将其导入回 Xcode 时,只显示一条警告:“空翻译”。

我似乎无法在这里找到问题 - 我的文件语法是正确的 - 每个“trans-unit”节点都有一个“源”,一个“目标”和一个“注释”子节点。

它甚至可以在预览中读取翻译: 在此输入图像描述

可能出了什么问题?有什么提示吗?

xcode translation localization ios

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