Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webmagic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
webmagic
Commits
dde2d89b
Commit
dde2d89b
authored
May 08, 2014
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ignore content in json when bracket when remove padding #124
parent
2913da47
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
4 deletions
+12
-4
pom.xml
pom.xml
+1
-1
Json.java
...re/src/main/java/us/codecraft/webmagic/selector/Json.java
+3
-3
JsonTest.java
...rc/test/java/us/codecraft/webmagic/selector/JsonTest.java
+8
-0
No files found.
pom.xml
View file @
dde2d89b
...
@@ -88,7 +88,7 @@
...
@@ -88,7 +88,7 @@
<dependency>
<dependency>
<groupId>
us.codecraft
</groupId>
<groupId>
us.codecraft
</groupId>
<artifactId>
xsoup
</artifactId>
<artifactId>
xsoup
</artifactId>
<version>
0.2.
2
</version>
<version>
0.2.
3
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
com.alibaba
</groupId>
...
...
webmagic-core/src/main/java/us/codecraft/webmagic/selector/Json.java
View file @
dde2d89b
package
us
.
codecraft
.
webmagic
.
selector
;
package
us
.
codecraft
.
webmagic
.
selector
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
org.jsoup.parser.
TokenQueue
;
import
us.codecraft.xsoup.X
TokenQueue
;
import
java.util.List
;
import
java.util.List
;
...
@@ -27,11 +27,11 @@ public class Json extends PlainText {
...
@@ -27,11 +27,11 @@ public class Json extends PlainText {
*/
*/
public
Json
removePadding
(
String
padding
)
{
public
Json
removePadding
(
String
padding
)
{
String
text
=
getText
();
String
text
=
getText
();
TokenQueue
tokenQueue
=
new
TokenQueue
(
text
);
XTokenQueue
tokenQueue
=
new
X
TokenQueue
(
text
);
tokenQueue
.
consumeWhitespace
();
tokenQueue
.
consumeWhitespace
();
tokenQueue
.
consume
(
padding
);
tokenQueue
.
consume
(
padding
);
tokenQueue
.
consumeWhitespace
();
tokenQueue
.
consumeWhitespace
();
String
chompBalanced
=
tokenQueue
.
chompBalanced
(
'('
,
')'
);
String
chompBalanced
=
tokenQueue
.
chompBalanced
NotInQuotes
(
'('
,
')'
);
return
new
Json
(
chompBalanced
);
return
new
Json
(
chompBalanced
);
}
}
...
...
webmagic-core/src/test/java/us/codecraft/webmagic/selector/JsonTest.java
View file @
dde2d89b
...
@@ -12,9 +12,17 @@ public class JsonTest {
...
@@ -12,9 +12,17 @@ public class JsonTest {
private
String
text
=
"callback({\"name\":\"json\"})"
;
private
String
text
=
"callback({\"name\":\"json\"})"
;
private
String
textWithBrackerInContent
=
"callback({\"name\":\"json)\"})"
;
@Test
@Test
public
void
testRemovePadding
()
throws
Exception
{
public
void
testRemovePadding
()
throws
Exception
{
String
name
=
new
Json
(
text
).
removePadding
(
"callback"
).
jsonPath
(
"$.name"
).
get
();
String
name
=
new
Json
(
text
).
removePadding
(
"callback"
).
jsonPath
(
"$.name"
).
get
();
assertThat
(
name
).
isEqualTo
(
"json"
);
assertThat
(
name
).
isEqualTo
(
"json"
);
}
}
@Test
public
void
testRemovePaddingForQuotes
()
throws
Exception
{
String
name
=
new
Json
(
textWithBrackerInContent
).
removePadding
(
"callback"
).
jsonPath
(
"$.name"
).
get
();
assertThat
(
name
).
isEqualTo
(
"json)"
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment