在不同数据源之间映射值
是否有机会获得一种简单的方法来在 android contentprovider 和基于 JSON 的服务器之间同步数据(在本例中为联系人)?
我的问题是,android 使用光标和其他东西,而另一方面我有 JSON 格式。第二个问题:相同的值现在有两个不同的名称,所以我需要在两个不同数据源中的值之间建立一种映射。
我的第一个方法是定义一个“用户”类。我将有不同的方法来填充数据和不同的方法来获取数据。问题是,使用这种方法我必须在每个方法中进行 android contentprovider 和 JSON 服务器之间的映射,例如
AndroidContact->(Mapping)->User-Object->(Mapping)->JSON-格式
JSON-Format->(Mapping)->-User-Object->(Mapping)->AndroidContact
如您所见,对于整个通信我需要至少进行四次映射,这真的很痛苦,因为我正在同步联系人可以拥有的所有信息,这相当多。
因此,我正在寻找一种巧妙的方法来将我的 Android 联系人与 JSON 服务器同步,而无需多次定义整个映射内容。
希望我能说清楚我在寻找什么。如果没有请随时询问。
干杯 L0rdAli3n
Is there any chance to get a easy way to sync data, in this case contacts, between the android contentprovider and a JSON-based server?
My problem is, that android uses the cursors and stuff and on the other side I have the JSON-Format. Second problem: the same value have now two different names, so I need a kind of mapping between values in the two different data sources.
My first approach was to define a "User"-Class. Where I would have different methods to fill it with data and different methods to get the data back. The problem is, that with this approach I have to do the mapping between android contentprovider and JSON server in every single method, e.g.
AndroidContact->(Mapping)->User-Object->(Mapping)->JSON-Format
JSON-Format->(Mapping)->-User-Object->(Mapping)->AndroidContact
As you can see, for the whole communication I need to do the mapping at least four times, which is really a pain in the ass, because I'm syncing ALL informations a contact can have, which is quite much.
So I'm searching for a clever way to sync my android contacts with an JSON server, without defining the whole mapping stuff more than once.
Hopefully I could make it clear, what I'm searching for. If not feel free to ask.
Cheers L0rdAli3n
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一天在网上搜索针对我的问题的现有解决方案(我不想重新发明轮子),我想出了以下解决方案:
我添加了一个 MappingContentProvider 来保存映射信息以及填充用户类的所有这些方法现在可以使用数据或从中取回数据。
After another day searching the web for a preexisting solution for my problem (I didn't want to reinvent the wheel) I came up with the following solution:
I added a MappingContentProvider to hold the mapping informations and all those methods filling the User-Class with data or get the data back from it can now use it.
您可以使用 MatrixCursor 返回 xml 或 json 格式的数据。
MatrixCursor :由对象数组支持的可变游标实现。
You can use MatrixCursor to return data that you have either in xml or json format.
MatrixCursor : A mutable cursor implementation backed by an array of Objects.