---
title: "stringifyQuery"
description: "将键值对对象序列化为 URL 查询字符串，支持数组参数和特殊字符的自动编码。"
seo_title: "stringifyQuery"
seo_description: "Serialize a query parameters object into a query string, with options for how repeated array values are formatted in the output."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/url/stringify-query"
---
# stringifyQuery

> 将键值对对象序列化为 URL 查询字符串，支持数组参数和特殊字符的自动编码。

## 用法

`stringifyQuery` 函数用于将对象序列化为查询字符串。

```ts
import { stringifyQuery } from '@movk/core'

stringifyQuery({ name: 'John', age: 30 })
// 'name=John&age=30'

stringifyQuery({ tags: ['a', 'b', 'c'] })
// 'tags=a&tags=b&tags=c'

stringifyQuery({ name: '中文' })
// 'name=%E4%B8%AD%E6%96%87'

stringifyQuery({ a: null, b: undefined, c: '' }, { skipNull: true, skipEmpty: true })
// ''
```

## API

### `stringifyQuery(params, options?)`

将对象序列化为查询字符串。

### 参数

**params** (`QueryParams`) *required*: 查询参数对象。

**options** (`object`): 序列化选项。

**options.skipNull** (`boolean`): 跳过 null 和 undefined 值。

**options.skipEmpty** (`boolean`): 跳过空字符串。

**options.arrayFormat** (`'repeat' | 'bracket' | 'index' | 'comma'`): 数组格式:repeat(默认)、bracket、index、comma。

### 返回值

**返回值** (`string`): 查询字符串(不含 ?)。

## Changelog

See commit history for [src/utilities/url/query.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/url/query.ts).


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
