pyspark rdd转json字符串

+--------+--------------------+
|objectid|           $geometry|
+--------+--------------------+
|       5|[106.366970696000...|
+--------+--------------------+
print(df1.toJSON().collect())
print(df1.toJSON().map(lambda str_json: json.loads(str_json)).collect())
 ['{"objectid":5,"$geometry":{"x":106.36697069600007,"y":37.85252578200004}}']
 [{'objectid': 5, '$geometry': {'x': 106.36697069600007, 'y': 37.85252578200004}}]
+---+---------+----------------+
| Id|     Name|       $geometry|
+---+---------+----------------+
| 43|Feature 1|[-104.44, 34.83]|
| 67|Feature 2|[-100.65, 33.69]|
+---+---------+----------------+

[{'Id': 43, 'Name': 'Feature 1', '$geometry': {'x': -104.44, 'y': 34.83}}, {'Id': 67, 'Name': 'Feature 2', '$geometry': {'x': -100.65, 'y': 33.69}}]


posted @ 2022-09-30 14:22  leechg  阅读(207)  评论(0编辑  收藏  举报