用于 Java 应用程序的 Python Web 服务? [英] Python web service for a java application?

查看:35
本文介绍了用于 Java 应用程序的 Python Web 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是一个愚蠢的问题,请原谅我.我对构建 Web 服务和完整的 Web 应用程序完全陌生.我想为基于 Java 的 Web 应用程序开发特定功能.但是,使用 Python 开发此功能更简单.那么,如果我使用 Python 开发此 Web 服务并将其用于基于 Java 的 Web 应用程序,是否有可能?

Forgive me if this is a stupid question. I am completely new to building web services and complete web apps. I want to develop a particular functionality for a java based web application. However this functionality is simpler to develop with Python. So is it possible If i develop this web service with Python and use it for a Java based webapp?

推荐答案

我认为这是可能的.让我们假设您的 webservice 方法返回一个 json 字符串.您可以使用此字符串,在 Java 中转换为 HashMap 并处理数据.

I think it is possible. Let's assume that your webservice method returns a json string. You can use this string, convert into a HashMap in Java and work with the data.

我个人更喜欢 cherrypy,因为它易于创建网络服务.它也有一个内置的服务器.

I personally prefer cherrypy, for the ease of creating a webservice. It has an inbuilt server too.

您可以使用 FlexJSON 将 json 字符串转换为 HashMap.方法反序列化将有助于这样做.我就是这样做的.

You can use FlexJSON to convert json string into a HashMap. The method deserialize will help in doing so. This is how I did it.

public Map<String, Object> JsonToMap(String data) {
        Map<String, Object> dataMap;
        dataMap = new JSONDeserializer<Map>().deserialize(data);
        return dataMap;
    }

这里,字符串数据是你的python webservice方法应该返回的json字符串.

Here, String data is the json string that your python webservice method is supposed to return.

这篇关于用于 Java 应用程序的 Python Web 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆