Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
e47a147c
authored
2013-08-06 16:37:41 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
serverJson Supoort 中文编码
1 parent
4ecb9cc3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
1 deletions
controller.go
utils.go
controller.go
View file @
e47a147
...
...
@@ -214,13 +214,16 @@ func (c *Controller) Abort(code string) {
panic
(
code
)
}
func
(
c
*
Controller
)
ServeJson
()
{
func
(
c
*
Controller
)
ServeJson
(
encoding
...
bool
)
{
content
,
err
:=
json
.
MarshalIndent
(
c
.
Data
[
"json"
],
""
,
" "
)
if
err
!=
nil
{
http
.
Error
(
c
.
Ctx
.
ResponseWriter
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
c
.
Ctx
.
ResponseWriter
.
Header
()
.
Set
(
"Content-Type"
,
"application/json;charset=UTF-8"
)
if
len
(
encoding
)
>
0
&&
encoding
[
0
]
==
true
{
content
=
[]
byte
(
stringsToJson
(
string
(
content
)))
}
c
.
writeToWriter
(
content
)
}
...
...
utils.go
View file @
e47a147
...
...
@@ -232,3 +232,17 @@ func ParseForm(form url.Values, obj interface{}) error {
}
return
nil
}
func
stringsToJson
(
str
string
)
string
{
rs
:=
[]
rune
(
str
)
jsons
:=
""
for
_
,
r
:=
range
rs
{
rint
:=
int
(
r
)
if
rint
<
128
{
jsons
+=
string
(
r
)
}
else
{
jsons
+=
"
\\
u"
+
strconv
.
FormatInt
(
int64
(
rint
),
16
)
// json
}
}
return
jsons
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment