小编CL *_* So的帖子

当在php中将对象推送到数组时,所有对象都是相同的

我想将许多对象推入数组

每个对象都有不同的价值

但是当我把它们推入阵列时

它们的所有值都是相同的

如何解决这个问题呢?

$sql="select password, mail from account";
$result=mysql_query($sql);
$arr=array();
while($row=mysql_fetch_assoc($result))
{
    $o->pw=$row['password'];
    $o->mail=$row['mail'];
    array_push($arr, $o);
}
echo json_encode($arr);
Run Code Online (Sandbox Code Playgroud)

php arrays json object

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

ACCESS_COARSE_LOCATION在Android 6上不起作用

我按照官方的例子来写这个程序

public class BluetoothActivity extends AppCompatActivity {
    private static final long SCANNING_TIMEOUT = 5000; /* 5 seconds */
    private static final int ENABLE_BT_REQUEST_ID = 1;
    private BleWrapper mBleWrapper = null;
    private boolean mScanning = false;
    private Handler mHandler = new Handler();
    private BluetoothAdapter mBluetoothAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bluetooth);
        if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
            Toast.makeText(this, "no ble", Toast.LENGTH_SHORT).show();
            finish();
        }
        final BluetoothManager bluetoothManager =
                (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
        mBluetoothAdapter = bluetoothManager.getAdapter();
        if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
            Intent enableBtIntent = …
Run Code Online (Sandbox Code Playgroud)

android bluetooth-lowenergy android-bluetooth

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

如何使用swift将方向度转换为文本?

我有一个 oc 版本

public class Heading
{
    private string[] m_names[]=new string[8] { "N","NE","E","SE","S","SW","W","NW" };
    public string this[float angle]{get{return m_names[((int)((angle-22.5f)/45.0f))&7]}}
}
Run Code Online (Sandbox Code Playgroud)

然后我转换为 swift 版本

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {        
    let trueHeading = newHeading.trueHeading
    let angle = Double.pi / 180 * trueHeading

    let dir = [ "N","NE","E","SE","S","SW","W","NW" ]
    let dir2=dir[(((trueHeading-22.5)/45.0)) as Int & 7]
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用,这一行出现错误“预期的','分隔符”

let dir2=dir[(((trueHeading-22.5)/45.0)) as Int & 7]
Run Code Online (Sandbox Code Playgroud)

swift swift4

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

如何在Kotlin中使用gson反序列化到ArrayList

我使用此类存储数据

public class Item(var name:String,
                  var description:String?=null){
}
Run Code Online (Sandbox Code Playgroud)

并在ArrayList中使用

public var itemList = ArrayList<Item>()
Run Code Online (Sandbox Code Playgroud)

使用此代码序列化对象

val gs=Gson()
val itemListJsonString = gs.toJson(itemList)
Run Code Online (Sandbox Code Playgroud)

并反序列化

itemList = gs.fromJson<ArrayList<Item>>(itemListJsonString, ArrayList::class.java)
Run Code Online (Sandbox Code Playgroud)

但是这个方法会给我LinkedTreeMap,而不是Item,我不能将LinkedTreeMap投射到Item

在Kotlin中反序列化为json的正确方法是什么?

android gson kotlin

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

如何禁用TabLayout上的点击效果?

如何禁用此点击效果?

在此输入图像描述

我试图将这些添加到Activity的主题但不起作用

<item name="tabIndicatorColor">@android:color/transparent</item>
<item name="tabBackground">@android:color/transparent</item>
<item name="tabTextAppearance">@android:color/transparent</item>
<item name="tabSelectedTextColor">@android:color/transparent</item>
Run Code Online (Sandbox Code Playgroud)

我也尝试直接在TabLayout中使用主题,但应用程序将崩溃

并尝试过android:stateListAnimator,但仍然无法正常工作

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    style="@style/AppTheme"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stateListAnimator="@null">
Run Code Online (Sandbox Code Playgroud)

android android-tablayout

4
推荐指数
3
解决办法
3159
查看次数

如何通过servlet中的ajax获取数据?

我想将页面上的一些数据发送到servlet

所以我写了下面的jquery来做这件事

我使用所有数据来构建一个json字符串,并直接将其发送到servlet

但我不知道如何从servlet中的ajax获取整个数据

$("#save").click
(
    function()
    {
        $.ajax
        (
            {
                url:'/WebApplication1/Controller',
                data:'{"name":"abc","address":"cde"}',
                type:'post',
                cache:false,
                success:function(data){alert(data);},
                error:function(){alert('error');}
            }
        );
    }
);
Run Code Online (Sandbox Code Playgroud)

如果从chrome看到请求标头的Form Data段

你会看到整个json字符串是关键.

Request URL:http://192.168.0.13/WebApplication1/Controller
Request Method:POST
Status Code:404 Not Found
Request Headersview source
Accept:*/*
Accept-Charset:Big5,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:112
Content-Type:application/x-www-form-urlencoded
Host:192.168.0.13
Origin:http://192.168.0.13
Referer:http://192.168.0.13/system_admin/building.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.910.0 Safari/535.7
X-Requested-With:XMLHttpRequest
Form Dataview URL encoded
{"name":"abc","address":"cde"}:
Response Headersview source
Accept-Ranges:bytes
Connection:Keep-Alive
Content-Language:en
Content-Type:text/html; charset=iso-8859-1
Date:Wed, 15 Feb 2012 12:37:24 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.2.14 (Win32) …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery json servlets

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

Android线性布局,如何匹配剩余的父级?

我将创建一个listview,底部有两个按钮

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

        <ListView
                android:layout_width="match_parent"
                android:layout_height="400dp"
                android:id="@android:id/list"></ListView>
    </LinearLayout>


    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

        <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_weight="1"
                android:text="Add Task"
                android:id="@+id/addTaskButton"></Button>
        <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight="1"
                android:text="Add Task2"
                android:id="@+id/addTaskButton2"></Button>
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

如何使listview与其余父级匹配高度?

如果我将高度设置为listview

            android:layout_height="400dp"
Run Code Online (Sandbox Code Playgroud)

这不适合所有设备

如果我设置了match_parent

            android:layout_height="match_parent"
Run Code Online (Sandbox Code Playgroud)

列表视图将覆盖底部的按钮

android android-layout android-listview android-linearlayout

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

如何等待所有异步任务在Node.js中完成?

我的程序需要运行许多异步任务.

所有异步任务完成后,必须运行一项任务.

如何让这个函数等待所有异步函数?

let urls=[....]

for(var i=0; i<urls.length; i++){
    doRequest(urls[i])
}
finish()



function doRequest(url){
    request({
      uri: url,
    }, function(error, response, body) {
        //do some tasks
    });
}

function finish(){
    console.log('finish')
}
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous node.js

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

ajax和php(或其他服务器语言)哪个更好?

请先看下面的例子,哪个更好?

你能比较一些方面,比如性能,编程,设计,负载,用户体验,维护,安全性或我没想到的任何其他方面.

这些方面可以帮助我决定哪一个更好吗?

<script>
$(document).ready
(
    function()
    {
        var message={..something..};
        $.ajax
        (
            {
                url:'get_content.php',
                data:message,
                type:'post',
                cache:false,
                success:function(data)
                        {
                            foreach(data.array)
                            {
                                $('#content').append($('<tr><td>'+data.array[key]+'</td></tr>'));
                            }
                        },
                error:function(){alert('error');}
            }
        );
    }
);
</script>
<table id="content">
</table>
Run Code Online (Sandbox Code Playgroud)
<table id="content">
<?php
query sql;
while(row=fetch result)
{
    echo '<tr><td>'+row[field]+'</td></tr>';
}
?>
</table>
Run Code Online (Sandbox Code Playgroud)

javascript php ajax jquery

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

如何在android中按回按钮后停止finish()方法?

我可以检查完成中的某些条件()

如果条件成功,继续回到上一个

否则,停止完成,并保持当前的活动?

java android

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

如何在应用程序中使用getSharedPreferences?

我试着打电话getSharedPreferences申请......

public class App extends Application{
    public App() {
        SharedPreferences prefs = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    }
}
Run Code Online (Sandbox Code Playgroud)

......但我有一个NullPointerException:

java.lang.NullPointerException: Attempt to invoke virtual method
  'android.content.SharedPreferences
  android.content.Context.getSharedPreferences(java.lang.String, int)' 
  on a null object reference
Run Code Online (Sandbox Code Playgroud)

我也试过这个并得到了同样的例外:

Context con = getApplicationContext();
Run Code Online (Sandbox Code Playgroud)

我该怎么打电话getSharedPreferences

android android-sharedpreferences

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

如何写一个kotlin数据类来匹配json?

我正在使用Retrofit来调用API并使用converter-gson将响应json转换为kotlin

这是回应

{
    "id": "1",
    "rank": "1",
    "name": "Challenge",
    "status": "E",
    "createDate": "2018-09-17 15:01:28",
    "lastModDate": "2018-09-17 15:06:32",
    "category": "DINING",
    "photo": {
        "path": "http://example.com/xxx.jpg",
        "size": [
            400,
            267
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

这是数据类.

data class ServiceList (val id:Int,
                        val rank:Int,
                        val name:String,
                        val status:String,
                        val lastModDate:String,
                        val category:String,
                        ???????)
Run Code Online (Sandbox Code Playgroud)

如何完成这门课程?

json kotlin data-class

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

如何在html中为无线电组列表命名无线电?

我希望它会发出一份颜色列表.在html中,如果输入是列表,它们应该是同名,但是同名的无线电输入,它们将在同一组中,那么如何分隔每个无线电组,但是所有组仍然具有相同的名称,那么我可以使用循环去获取服务器端列表的所有值?

此外,在客户端,我需要检查是否每个组都被选中,所以如何使用javascript或jquery来选择所有的无线电组,而不是所有的单选按钮.

<form method="post">
Car A: <input type="radio" name="color[]"/>red <input type="radio" name="color[]"/>yello<br/>
Car B: <input type="radio" name="color[]"/>red <input type="radio" name="color[]"/>yello<br/>
Car C: <input type="radio" name="color[]"/>red <input type="radio" name="color[]"/>yello<br/>
<input type="submit"/>
</form>
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

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