Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
json-editor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IOPSYS
json-editor
Commits
3afe5ea6
Commit
3afe5ea6
authored
5 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
support more complex array manipulation
parent
2cdebf74
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api.c
+19
-7
19 additions, 7 deletions
api.c
with
19 additions
and
7 deletions
api.c
+
19
−
7
View file @
3afe5ea6
...
@@ -153,6 +153,9 @@ int set_by_string(char *fmt, struct json_object **src, char *val, enum json_type
...
@@ -153,6 +153,9 @@ int set_by_string(char *fmt, struct json_object **src, char *val, enum json_type
*
src
=
json_object_new_object
();
*
src
=
json_object_new_object
();
}
}
printf
(
"format = %s
\n
"
,
fmt
);
printf
(
"set val = %s
\n
"
,
val
);
ptr
=
tmp
=
*
src
;
ptr
=
tmp
=
*
src
;
strcpy
(
buffer
,
fmt
);
strcpy
(
buffer
,
fmt
);
...
@@ -164,16 +167,18 @@ int set_by_string(char *fmt, struct json_object **src, char *val, enum json_type
...
@@ -164,16 +167,18 @@ int set_by_string(char *fmt, struct json_object **src, char *val, enum json_type
/* if next key exists, parse prev key, let switch-case add/alter last key */
/* if next key exists, parse prev key, let switch-case add/alter last key */
if
(
p
)
{
if
(
p
)
{
/* TODO: pretty wonky order with get idx first to overwrite braces?*/
idx
=
get_idx
(
prev
);
json_object_object_get_ex
(
tmp
,
prev
,
&
ptr
);
json_object_object_get_ex
(
tmp
,
prev
,
&
ptr
);
/* if we need to step further and currently marked value isnt an object, we need to overwrite it */
/* if we need to step further and currently marked value isnt an object, we need to overwrite it */
if
(
!
json_object_is_type
(
ptr
,
json_type_object
))
{
if
(
!
json_object_is_type
(
ptr
,
json_type_object
)
&&
!
json_object_is_type
(
ptr
,
json_type_array
))
{
printf
(
"lets create new object hahah! key = %s
\n
"
,
prev
);
ptr
=
json_object_new_object
();
ptr
=
json_object_new_object
();
json_object_object_add
(
tmp
,
prev
,
ptr
);
json_object_object_add
(
tmp
,
prev
,
ptr
);
}
}
printf
(
"p=%s
\n
"
,
p
);
printf
(
"p=%s
\n
"
,
p
);
/* TODO: if prev contains [x], get idx of x */
/* TODO: if prev contains [x], get idx of x */
idx
=
get_idx
(
prev
);
printf
(
"%s %d
\n
"
,
__func__
,
__LINE__
);
printf
(
"%s %d
\n
"
,
__func__
,
__LINE__
);
/* TODO: make enums for rv of get_idx */
/* TODO: make enums for rv of get_idx */
if
(
idx
!=
-
2
)
{
if
(
idx
!=
-
2
)
{
...
@@ -220,8 +225,15 @@ int set_by_string(char *fmt, struct json_object **src, char *val, enum json_type
...
@@ -220,8 +225,15 @@ int set_by_string(char *fmt, struct json_object **src, char *val, enum json_type
return
-
1
;
return
-
1
;
}
}
json_object_object_foreach
(
parsed_val
,
key1
,
val1
)
/* TODO: does this actually work? what would be the test case for this? */
json_object_object_add
(
*
src
,
key1
,
val1
);
idx
=
get_idx
(
prev
);
if
(
idx
==
-
2
)
{
json_object_object_foreach
(
parsed_val
,
key1
,
val1
)
json_object_object_add
(
*
src
,
key1
,
val1
);
}
else
{
printf
(
"%s %d
\n
"
,
__func__
,
__LINE__
);
add_array
(
ptr
,
idx
,
val
,
type
,
prev
);
}
}
}
break
;
break
;
case
json_type_string
:
case
json_type_string
:
...
@@ -350,15 +362,15 @@ int main()
...
@@ -350,15 +362,15 @@ int main()
printf
(
"tets_arr = %s
\n
"
,
json_object_get_string
(
obj_arr
));
printf
(
"tets_arr = %s
\n
"
,
json_object_get_string
(
obj_arr
));
printf
(
"
%s %d
obj=%s
\n
"
,
__func__
,
__LINE__
,
json_object_get_string
(
obj
));
printf
(
"
original
obj=%s
\n
"
,
json_object_get_string
(
obj
));
ptr
=
get
(
"nested"
,
obj
);
ptr
=
get
(
"nested"
,
obj
);
printf
(
"%s
\n
"
,
json_object_get_string
(
ptr
));
printf
(
"%s
\n
"
,
json_object_get_string
(
ptr
));
set_by_string
(
"test.apdfgj[
0]
"
,
&
obj
,
"
1
"
,
json_type_string
);
set_by_string
(
"test.apdfgj[
1].test
"
,
&
obj
,
"
gå och häng dig
"
,
json_type_string
);
printf
(
"%s
\n
"
,
json_object_get_string
(
obj
));
printf
(
"
result:
%s
\n
"
,
json_object_get_string
(
obj
));
json_object_put
(
obj
);
json_object_put
(
obj
);
return
0
;
return
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment